MessageHandler.c 935 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243
  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. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //============================================
  80. // OCPP MeterValue request flag
  81. //============================================
  82. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  83. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  84. //=============================================
  85. // OCPP HeartBeat Response Not Receive Counts
  86. //============================================
  87. static int HeartBeatWithNOResponse = 0;
  88. extern sqlite3 *db;
  89. int TransactionMessageAttemptsGet(void);
  90. int TransactionMessageRetryIntervalGet(void);
  91. int GetOcppConnStatus(void);
  92. void SetOcppConnStatus(uint8_t status);
  93. int setKeyValue(char *key, char *value);
  94. void OCPP_get_TableAuthlocalAllData(void);
  95. void processUnkownKey(void);
  96. struct InterLock
  97. {
  98. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  99. unsigned char isGetDiagnosticGoing:1;
  100. unsigned char isUpdateFirmwareGoing:1;
  101. }interLock;
  102. struct ClientTime
  103. {
  104. struct timespec Heartbeat;
  105. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  106. struct timespec StartTransaction;
  107. struct timespec StopTransaction;
  108. struct timespec MeterValues[CONNECTOR_QUANTITY];
  109. struct timespec RemoteStartWait;
  110. struct timespec TcciQueryDeduct;
  111. }clientTime;
  112. typedef union
  113. {
  114. //Operations Initiated by Central System
  115. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  116. struct
  117. {
  118. //CsMsgValue[0]
  119. unsigned char StatusNotificationReq:1; //bit 0,
  120. unsigned char StatusNotificationConf:1; //bit 1,
  121. unsigned char TriggerMeterValue:1; //bit 2,
  122. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  123. unsigned char isOnCharging:1; //bit 4.
  124. unsigned char :3; //bit 5~7
  125. }bits[CONNECTOR_QUANTITY];
  126. }CpinitiateMsg;
  127. CpinitiateMsg cpinitateMsg;
  128. //GetConfiguration Array
  129. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  132. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  133. #if 0
  134. static char *ChargePointErrorCodeStr[] = {
  135. MACROSTR(ConnectorLockFailure),
  136. MACROSTR(EVCommunicationError),
  137. MACROSTR(GroundFailure),
  138. MACROSTR(HighTemperature),
  139. MACROSTR(InternalError),
  140. MACROSTR(LocalListConflict),
  141. MACROSTR(NoError),
  142. MACROSTR(OtherError),
  143. MACROSTR(OverCurrentFailure),
  144. MACROSTR(OverVoltage),
  145. MACROSTR(PowerMeterFailure),
  146. MACROSTR(PowerSwitchFailure),
  147. MACROSTR(ReaderFailure),
  148. MACROSTR(ResetFailure),
  149. MACROSTR(UnderVoltage),
  150. MACROSTR(WeakSignal)
  151. };
  152. #endif
  153. static char * ChargePointStatusStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Preparing),
  156. MACROSTR(Charging),
  157. MACROSTR(SuspendedEVSE),
  158. MACROSTR(SuspendedEV),
  159. MACROSTR(Finishing),
  160. MACROSTR(Reserved),
  161. MACROSTR(Unavailable),
  162. MACROSTR(Faulted)
  163. };
  164. static char *RegistrationStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Pending),
  167. MACROSTR(Rejected)
  168. };
  169. static char *AvailabilityTypeStr[] = {
  170. MACROSTR(Inoperative),
  171. MACROSTR(Operative)
  172. };
  173. static char *AvailabilityStatusStr[] = {
  174. MACROSTR(Accepted),
  175. MACROSTR(Rejected),
  176. MACROSTR(Scheduled)
  177. };
  178. static char *ConfigurationStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(RebootRequired),
  182. MACROSTR(NotSupported)
  183. };
  184. static char *ClearCacheStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected)
  187. };
  188. static char *ChargingProfilePurposeTypeStr[] = {
  189. MACROSTR(ChargePointMaxProfile),
  190. MACROSTR(TxDefaultProfile),
  191. MACROSTR(TxProfile)
  192. };
  193. static char *ChargingProfileStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected),
  196. MACROSTR(NotSupported)
  197. };
  198. static char *ClearChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Unknown)
  201. };
  202. static char *GetCompositeScheduleStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected)
  205. };
  206. static char *UpdateTypeStr[] = {
  207. MACROSTR(Differential),
  208. MACROSTR(Full)
  209. };
  210. static char *UpdateStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Failed),
  213. MACROSTR(NotSupported),
  214. MACROSTR(VersionMismatch)
  215. };
  216. static char *RemoteStartStopStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Rejected)
  219. };
  220. static char *ReservationStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Faulted),
  223. MACROSTR(Occupied),
  224. MACROSTR(Rejected),
  225. MACROSTR(Unavailable)
  226. };
  227. static char *ResetTypeStr[] = {
  228. MACROSTR(Hard),
  229. MACROSTR(Soft)
  230. };
  231. static char *ResetStatusStr[] = {
  232. MACROSTR(Accepted),
  233. MACROSTR(Rejected)
  234. };
  235. static char * DiagnosticsStatusStr[] = {
  236. MACROSTR(Idle),
  237. MACROSTR(Uploaded),
  238. MACROSTR(UploadFailed),
  239. MACROSTR(Uploading)
  240. };
  241. static char * FirmwareStatusStr[] = {
  242. MACROSTR(Downloaded),
  243. MACROSTR(DownloadFailed),
  244. MACROSTR(Downloading),
  245. MACROSTR(Idle),
  246. MACROSTR(InstallationFailed),
  247. MACROSTR(Installing),
  248. MACROSTR(Installed)
  249. };
  250. static char * MessageTriggerStr[] = {
  251. MACROSTR(BootNotification),
  252. MACROSTR(DiagnosticsStatusNotification),
  253. MACROSTR(FirmwareStatusNotification),
  254. MACROSTR(Heartbeat),
  255. MACROSTR(MeterValues),
  256. MACROSTR(StatusNotification)
  257. };
  258. static char * TriggerMessageStatusStr[] = {
  259. MACROSTR(Accepted),
  260. MACROSTR(Rejected),
  261. MACROSTR(NotImplemented)
  262. };
  263. static char * UnlockStatusStr[] = {
  264. MACROSTR(Unlocked),
  265. MACROSTR(UnlockFailed),
  266. MACROSTR(NotSupported)
  267. };
  268. #if 0
  269. static char * StopTransactionReasonStr[] = {
  270. MACROSTR(EmergencyStop),
  271. MACROSTR(EVDisconnected),
  272. MACROSTR(HardReset),
  273. MACROSTR(Local),
  274. MACROSTR(Other),
  275. MACROSTR(PowerLoss),
  276. MACROSTR(Reboot),
  277. MACROSTR(Remote),
  278. MACROSTR(SoftReset),
  279. MACROSTR(UnlockCommand),
  280. MACROSTR(DeAuthorized)
  281. };
  282. #endif
  283. static char * CancelReservationStatusStr[] = {
  284. MACROSTR(Accepted),
  285. MACROSTR(Rejected)
  286. };
  287. static char * ReadingContextStr[] = {
  288. MACROSTR(Interruption.Begin),
  289. MACROSTR(Interruption.End),
  290. MACROSTR(Other),
  291. MACROSTR(Sample.Clock),
  292. MACROSTR(Sample.Periodic),
  293. MACROSTR(Transaction.Begin),
  294. MACROSTR(Transaction.End),
  295. MACROSTR(Trigger)
  296. };
  297. static char * ValueFormatStr[] = {
  298. MACROSTR(Raw),
  299. MACROSTR(SignedData)
  300. };
  301. static char * MeasurandStr[] = {
  302. MACROSTR(Current.Export),
  303. MACROSTR(Current.Import),
  304. MACROSTR(Current.Offered),
  305. MACROSTR(Energy.Active.Export.Register),
  306. MACROSTR(Energy.Active.Import.Register),
  307. MACROSTR(Energy.Reactive.Export.Register),
  308. MACROSTR(Energy.Reactive.Import.Register),
  309. MACROSTR(Energy.Active.Export.Interval),
  310. MACROSTR(Energy.Active.Import.Interval),
  311. MACROSTR(Energy.Reactive.Export.Interval),
  312. MACROSTR(Energy.Reactive.Import.Interval),
  313. MACROSTR(Frequency),
  314. MACROSTR(Power.Active.Export),
  315. MACROSTR(Power.Active.Import),
  316. MACROSTR(Power.Factor),
  317. MACROSTR(Power.Offered),
  318. MACROSTR(Power.Reactive.ExportMACROSTR),
  319. MACROSTR(Power.Reactive.Import),
  320. MACROSTR(RPM),
  321. MACROSTR(SoC),
  322. MACROSTR(Temperature),
  323. MACROSTR(Voltage)
  324. };
  325. static char * LocationStr[] = {
  326. MACROSTR(Body),
  327. MACROSTR(Cable),
  328. MACROSTR(EV),
  329. MACROSTR(Inlet),
  330. MACROSTR(Outlet)
  331. };
  332. static char * PhaseStr[] = {
  333. MACROSTR(L1),
  334. MACROSTR(L2),
  335. MACROSTR(L3),
  336. MACROSTR(N),
  337. MACROSTR(L1-N),
  338. MACROSTR(L2-N),
  339. MACROSTR(L3-N),
  340. MACROSTR(L1-L2),
  341. MACROSTR(L2-L3),
  342. MACROSTR(L3-L1)
  343. };
  344. static char * UnitOfMeasureStr[] = {
  345. MACROSTR(Wh),
  346. MACROSTR(kWh),
  347. MACROSTR(varh),
  348. MACROSTR(kvarh),
  349. MACROSTR(W),
  350. MACROSTR(kW),
  351. MACROSTR(VA),
  352. MACROSTR(kVA),
  353. MACROSTR(var),
  354. MACROSTR(kvar),
  355. MACROSTR(A),
  356. MACROSTR(V),
  357. MACROSTR(Celsius),
  358. MACROSTR(Fahrenheit),
  359. MACROSTR(K),
  360. MACROSTR(Percent)
  361. };
  362. //=========================================
  363. // Save configuration
  364. //=========================================
  365. int runShellCmd(const char*cmd)
  366. {
  367. int result = FAIL;
  368. char buf[256];
  369. FILE *fp;
  370. fp = popen(cmd, "r");
  371. if(fp != NULL)
  372. {
  373. while(fgets(buf, sizeof(buf), fp) != NULL)
  374. {
  375. DEBUG_INFO("%s\n", buf);
  376. }
  377. result = PASS;
  378. }
  379. pclose(fp);
  380. return result;
  381. }
  382. int StoreUsrConfigData(struct SysConfigData *UsrData)
  383. {
  384. int result = PASS;
  385. int fd,wrd;
  386. unsigned int i,Chk;
  387. unsigned char *ptr, *BufTmp;
  388. int MtdBlockSize = 0x300000;
  389. Chk=0;
  390. ptr=(unsigned char *)UsrData;
  391. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  392. {
  393. memset(BufTmp,0,MtdBlockSize);
  394. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  395. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  396. Chk+=*(BufTmp+i);
  397. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  398. // Output configuration to file.
  399. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  400. if (fd < 0)
  401. {
  402. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. wrd=write(fd, BufTmp, MtdBlockSize);
  407. close(fd);
  408. if(wrd<MtdBlockSize)
  409. {
  410. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  411. free(BufTmp);
  412. return 0;
  413. }
  414. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  415. DEBUG_INFO("Erase /dev/mtd10.\n");
  416. runShellCmd("flash_erase /dev/mtd10 0 0");
  417. DEBUG_INFO("Write /dev/mtd10.\n");
  418. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  419. DEBUG_INFO("Erase /dev/mtd11.\n");
  420. runShellCmd("flash_erase /dev/mtd11 0 0");
  421. DEBUG_INFO("Write /dev/mtd11.\n");
  422. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  423. system("rm -f /mnt/EvseConfig.bin");
  424. DEBUG_INFO("EvseConfig write to flash OK\n");
  425. }
  426. else
  427. {
  428. DEBUG_ERROR("alloc BlockSize NG\r\n");
  429. result = FAIL;
  430. }
  431. if(BufTmp!=NULL)
  432. free(BufTmp);
  433. return result;
  434. }
  435. //=========================================
  436. // Sqlite3 related function
  437. //=========================================
  438. static int selectSqlCount = 0;
  439. static int callback(void *data, int argc, char **argv, char **azColName){
  440. int i;
  441. //printf("%s: ", (const char*)data);
  442. selectSqlCount = argc;
  443. for(i = 0; i<argc; i++){
  444. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  445. }
  446. //printf("\n");
  447. return 0;
  448. }
  449. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  450. //int i;
  451. //printf("%s:\n", (const char*)data);
  452. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  453. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  454. return 0;
  455. }
  456. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  457. //printf("%s:\n", (const char*)data);
  458. //idTag
  459. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  460. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  461. //parentIdTag
  462. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  463. //expir_date
  464. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  465. //status
  466. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  467. //version
  468. if(columenCount > 5)
  469. idTagQuery.listVersionInt = atoi(columnValue[5]);
  470. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  471. return 0;
  472. }
  473. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  474. {
  475. // localversion = argv[5] ? atoi(argv[5]) : 0;
  476. // printf("localversion=%d\n", localversion);
  477. return 0;
  478. }
  479. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  480. {
  481. for (int i = 0; i < n_columns; i++)
  482. {
  483. DEBUG_INFO("%s\t", col_values[i]);
  484. }
  485. DEBUG_INFO("\n");
  486. return 0;
  487. }
  488. int OCPP_cleanLocalCache()
  489. {
  490. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  491. char *errMsg = 0;
  492. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  493. if (SQLITE_OK != rc)
  494. {
  495. DEBUG_INFO("SQL error: %s\n",errMsg);
  496. return FALSE;
  497. }
  498. return TRUE;
  499. }
  500. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  501. {
  502. int isSuccess = TRUE;
  503. int ret = 0;
  504. //const char* data = "Callback function called";
  505. char sql[300];
  506. char zErrMsg[200];
  507. memset(sql, 0, 300);
  508. memset(zErrMsg, 0, 200);
  509. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  510. //* Execute SQL statement */
  511. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  512. if( ret != SQLITE_OK )
  513. {
  514. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  515. isSuccess = FALSE;
  516. }
  517. return isSuccess;
  518. }
  519. void OCPP_getIdTagFromLocalCache(char idTag[])
  520. {
  521. int rc = 0;
  522. char sql[100];
  523. char zErrMsg[100];
  524. memset(sql, 0, 100);
  525. memset(zErrMsg, 0, 100);
  526. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  527. memset(&idTagQuery, 0, sizeof(idTagQuery));
  528. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  529. /* Execute SQL statement */
  530. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  531. if( rc != SQLITE_OK )
  532. {
  533. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  534. }
  535. }
  536. void OCPP_getListVerion()
  537. {
  538. int rc = 0;
  539. // const char* data = "Callback function called";
  540. char sql[100];
  541. char zErrMsg[100];
  542. memset(sql, 0, 100);
  543. memset(zErrMsg, 0, 100);
  544. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  545. /* Execute SQL statement */
  546. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  547. if( rc != SQLITE_OK )
  548. {
  549. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  550. }
  551. }
  552. void OCPP_get_TableAuthlocalAllData(void)
  553. {
  554. int rc = 0;
  555. char sql[100];
  556. char zErrMsg[100];
  557. memset(sql, 0, 100);
  558. memset(zErrMsg, 0, 100);
  559. sprintf(sql,"select * from ocpp_auth_local ");
  560. /* Execute SQL statement */
  561. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  562. if( rc != SQLITE_OK )
  563. {
  564. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  565. }
  566. //return ver;
  567. }
  568. int OCPP_cleanLocalList()
  569. {
  570. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  571. char *errMsg = 0;
  572. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  573. if (SQLITE_OK != rc)
  574. {
  575. DEBUG_INFO("%s\n",errMsg);
  576. return FALSE;
  577. }
  578. return TRUE;
  579. }
  580. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  581. {
  582. int isSuccess = FALSE;
  583. int ret = 0;
  584. //const char* data = "Callback function called";
  585. char sql[300];
  586. char zErrMsg[200];
  587. memset(sql, 0, 300);
  588. memset(zErrMsg, 0, 200);
  589. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  590. //* Execute SQL statement */
  591. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. memset(sql, 0, 300);
  598. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  599. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  600. if( ret != SQLITE_OK )
  601. {
  602. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  603. return isSuccess;
  604. }
  605. isSuccess = TRUE;
  606. return isSuccess;
  607. }
  608. void OCPP_getIdTagFromLocalList(char idTag[])
  609. {
  610. int rc = 0;
  611. // const char* data = "Callback function called";
  612. char sql[100];
  613. char zErrMsg[100];
  614. memset(sql, 0, 100);
  615. memset(zErrMsg, 0, 100);
  616. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  617. memset(&idTagQuery, 0, sizeof(idTagQuery));
  618. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  619. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  620. /* Execute SQL statement */
  621. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  622. if( rc != SQLITE_OK )
  623. {
  624. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  625. }
  626. //return ver;
  627. }
  628. void OCPP_deleteIdTagFromLocalList(char idTag[])
  629. {
  630. //int ver = 0;
  631. //int isSuccess = FALSE;
  632. int rc = 0;
  633. char sql[100];
  634. char zErrMsg[100];
  635. memset(sql, 0, 100);
  636. memset(zErrMsg, 0, 100);
  637. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  638. //* Execute SQL statement */
  639. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  640. if( rc != SQLITE_OK )
  641. {
  642. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  643. }
  644. }
  645. int getCurrentYear()
  646. {
  647. int result = 0;
  648. time_t CurrentTime;
  649. struct tm *tm;
  650. CurrentTime = time(NULL);
  651. tm=localtime(&CurrentTime);
  652. result = (tm->tm_year + 1900);
  653. return result;
  654. }
  655. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  656. {
  657. int result = PASS;
  658. char* errMsg = NULL;
  659. char sqlStr[8192];
  660. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  661. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  662. {
  663. result = FAIL;
  664. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  665. }
  666. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  667. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  668. {
  669. result = FAIL;
  670. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  671. }
  672. return result;
  673. }
  674. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  675. {
  676. int result = PASS;
  677. char* errMsg = NULL;
  678. char sqlStr[8192];
  679. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  680. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  681. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  682. {
  683. result = FAIL;
  684. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  685. }
  686. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  687. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  688. {
  689. result = FAIL;
  690. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  691. }
  692. return result;
  693. }
  694. int OCPP_update_deduct_info(int txId, char *creditNo)
  695. {
  696. int result = PASS;
  697. char* errMsg = NULL;
  698. char sqlStr[8192];
  699. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  700. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  701. {
  702. result = FAIL;
  703. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  704. }
  705. return result;
  706. }
  707. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  708. {
  709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  710. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  711. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  712. atoi(columnValue[1]),
  713. columnValue[2],
  714. atoi(columnValue[3])==1?"true":"false",
  715. atoi(columnValue[4])==1?"true":"false",
  716. columnValue[5],
  717. columnValue[9]);
  718. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  719. return 0;
  720. }
  721. void OCPP_query_deduct_info()
  722. {
  723. int rc = 0;
  724. char sql[100];
  725. char zErrMsg[100];
  726. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  727. /* Execute SQL statement */
  728. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  729. if( rc != SQLITE_OK )
  730. {
  731. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  732. }
  733. }
  734. void reportReaderStatus(int gun_index)
  735. {
  736. struct timeval tmnow;
  737. struct tm *tm;
  738. char buf[28];//, usec_buf[6];
  739. gettimeofday(&tmnow, NULL);
  740. time_t t;
  741. t = time(NULL);
  742. /*UTC time and date*/
  743. tm = gmtime(&t);
  744. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  745. #if 0 // remove temporally
  746. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  747. strcat(buf,".");
  748. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  749. strcat(buf,usec_buf);
  750. #endif
  751. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  752. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  753. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  754. (gun_index+1),
  755. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  756. buf,
  757. ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index],
  758. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].creditNo,
  759. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  760. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  761. }
  762. //==========================================
  763. // Check time passed since today
  764. //==========================================
  765. long long DiffTimebWithNow(struct timeb ST)
  766. {
  767. //return milli-second
  768. struct timeb ET;
  769. long long StartTime,StopTime;
  770. ftime(&ET);
  771. StartTime=(long long)ST.time;
  772. StopTime=(long long)ET.time;
  773. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  774. }
  775. int getTimePassSinceToday(uint8_t gun_index)
  776. {
  777. int result = -1;
  778. static time_t lastTime[4];
  779. time_t t;
  780. struct tm *tmStartToday;
  781. struct timeb tbStartToday;
  782. t=time(NULL);
  783. if(difftime(t, lastTime[gun_index])>0)
  784. {
  785. tmStartToday=localtime(&t);
  786. tmStartToday->tm_hour = 0;
  787. tmStartToday->tm_min = 0;
  788. tmStartToday->tm_sec = 0;
  789. tbStartToday.time = mktime(tmStartToday);
  790. tbStartToday.millitm = 0;
  791. result = DiffTimebWithNow(tbStartToday)/1000;
  792. lastTime[gun_index] = t;
  793. }
  794. return result;
  795. }
  796. void getNowDatetime(uint8_t *data)
  797. {
  798. time_t t = time(NULL);
  799. struct tm tm = *localtime(&t);
  800. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  801. }
  802. int syncDateTimeRTC(uint8_t *data)
  803. {
  804. struct ParsingResult
  805. {
  806. int result;
  807. int scanedElement;
  808. int year;
  809. int month;
  810. int mday;
  811. int hour;
  812. int min;
  813. int sec;
  814. int tz_hour;
  815. int tz_min;
  816. float minSec;
  817. }result;
  818. struct tm tmOrg;
  819. struct tm *tmTarget;
  820. struct timeb tbTarget;
  821. char buf[128];
  822. memset(&result, 0x00, sizeof(struct ParsingResult));
  823. result.result = PASS;
  824. if(strstr((char*)data, ".") != NULL)
  825. {
  826. // Original data with mini second
  827. if(strstr((char*)data, "Z") != NULL)
  828. {
  829. // Original data with Z
  830. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  831. &result.year,
  832. &result.month,
  833. &result.mday,
  834. &result.hour,
  835. &result.min,
  836. &result.sec,
  837. &result.minSec);
  838. }
  839. else
  840. {
  841. // Original data without Z
  842. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  843. &result.year,
  844. &result.month,
  845. &result.mday,
  846. &result.hour,
  847. &result.min,
  848. &result.sec,
  849. &result.minSec,
  850. &result.tz_hour,
  851. &result.tz_min);
  852. }
  853. }
  854. else
  855. {
  856. // Original data without mini second
  857. if(strstr((char*)data, "Z") != NULL)
  858. {
  859. // Original data with Z
  860. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  861. &result.year,
  862. &result.month,
  863. &result.mday,
  864. &result.hour,
  865. &result.min,
  866. &result.sec);
  867. }
  868. else
  869. {
  870. // Original data without Z
  871. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  872. &result.year,
  873. &result.month,
  874. &result.mday,
  875. &result.hour,
  876. &result.min,
  877. &result.sec,
  878. &result.tz_hour,
  879. &result.tz_min);
  880. }
  881. }
  882. tmOrg.tm_year = result.year - 1900;
  883. tmOrg.tm_mon = result.month - 1;
  884. tmOrg.tm_mday = result.mday;
  885. tmOrg.tm_hour = result.hour;
  886. tmOrg.tm_min = result.min;
  887. tmOrg.tm_sec = result.sec;
  888. tmOrg.tm_gmtoff = 0;
  889. tbTarget.time = mktime(&tmOrg);
  890. tbTarget.timezone = 0;
  891. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  892. tmTarget = gmtime(&tbTarget.time);
  893. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  894. //DEBUG_INFO(" org date time: %s\n", data);
  895. //DEBUG_INFO("parse date time: %s\n", buf);
  896. system(buf);
  897. system("/sbin/hwclock -w --systohc");
  898. if(result.scanedElement < 6)
  899. result.result = FAIL;
  900. return result.result;
  901. }
  902. //==========================================
  903. // GetCompositeSchedule logic related function
  904. //==========================================
  905. int DiffTimebSec(struct timeb ST, struct timeb ET)
  906. {
  907. //return milli-second
  908. unsigned int StartTime,StopTime;
  909. StartTime=(unsigned int)ST.time;
  910. StopTime=(unsigned int)ET.time;
  911. return (StopTime-StartTime);
  912. }
  913. int DiffTimebWithNowSec(struct timeb ST)
  914. {
  915. //return milli-second
  916. struct timeb ET;
  917. unsigned int StartTime,StopTime;
  918. ftime(&ET);
  919. StartTime=(unsigned int)ST.time;
  920. StopTime=(unsigned int)ET.time;
  921. return (StopTime-StartTime);
  922. }
  923. int getStartStop(uint8_t *start, uint8_t *stop)
  924. {
  925. struct ParsingResult
  926. {
  927. int result;
  928. int scanedElement;
  929. int year;
  930. int month;
  931. int mday;
  932. int hour;
  933. int min;
  934. int sec;
  935. int tz_hour;
  936. int tz_min;
  937. float minSec;
  938. };
  939. struct ParsingResult parseStart;
  940. struct ParsingResult parseStop;
  941. int result = -1;
  942. struct tm tmStart;
  943. struct timeb tbStart;
  944. struct tm tmStop;
  945. struct timeb tbStop;
  946. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  947. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  948. // Scan start & stop date time
  949. if(strstr((char*)start, ".") != NULL)
  950. {
  951. // Original data with mini second
  952. if(strstr((char*)start, "Z") != NULL)
  953. {
  954. // Original data with Z
  955. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  956. &parseStart.year,
  957. &parseStart.month,
  958. &parseStart.mday,
  959. &parseStart.hour,
  960. &parseStart.min,
  961. &parseStart.sec,
  962. &parseStart.minSec);
  963. }
  964. else
  965. {
  966. // Original data without Z
  967. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  968. &parseStart.year,
  969. &parseStart.month,
  970. &parseStart.mday,
  971. &parseStart.hour,
  972. &parseStart.min,
  973. &parseStart.sec,
  974. &parseStart.minSec,
  975. &parseStart.tz_hour,
  976. &parseStart.tz_min);
  977. }
  978. }
  979. else
  980. {
  981. // Original data without mini second
  982. if(strstr((char*)start, "Z") != NULL)
  983. {
  984. // Original data with Z
  985. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  986. &parseStart.year,
  987. &parseStart.month,
  988. &parseStart.mday,
  989. &parseStart.hour,
  990. &parseStart.min,
  991. &parseStart.sec);
  992. }
  993. else
  994. {
  995. // Original data without Z
  996. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  997. &parseStart.year,
  998. &parseStart.month,
  999. &parseStart.mday,
  1000. &parseStart.hour,
  1001. &parseStart.min,
  1002. &parseStart.sec,
  1003. &parseStart.tz_hour,
  1004. &parseStart.tz_min);
  1005. }
  1006. }
  1007. if(strstr((char*)stop, ".") != NULL)
  1008. {
  1009. // Original data with mini second
  1010. if(strstr((char*)stop, "Z") != NULL)
  1011. {
  1012. // Original data with Z
  1013. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1014. &parseStop.year,
  1015. &parseStop.month,
  1016. &parseStop.mday,
  1017. &parseStop.hour,
  1018. &parseStop.min,
  1019. &parseStop.sec,
  1020. &parseStop.minSec);
  1021. }
  1022. else
  1023. {
  1024. // Original data without Z
  1025. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1026. &parseStop.year,
  1027. &parseStop.month,
  1028. &parseStop.mday,
  1029. &parseStop.hour,
  1030. &parseStop.min,
  1031. &parseStop.sec,
  1032. &parseStop.minSec,
  1033. &parseStop.tz_hour,
  1034. &parseStop.tz_min);
  1035. }
  1036. }
  1037. else
  1038. {
  1039. // Original data without mini second
  1040. if(strstr((char*)stop, "Z") != NULL)
  1041. {
  1042. // Original data with Z
  1043. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1044. &parseStop.year,
  1045. &parseStop.month,
  1046. &parseStop.mday,
  1047. &parseStop.hour,
  1048. &parseStop.min,
  1049. &parseStop.sec);
  1050. }
  1051. else
  1052. {
  1053. // Original data without Z
  1054. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1055. &parseStop.year,
  1056. &parseStop.month,
  1057. &parseStop.mday,
  1058. &parseStop.hour,
  1059. &parseStop.min,
  1060. &parseStop.sec,
  1061. &parseStop.tz_hour,
  1062. &parseStop.tz_min);
  1063. }
  1064. }
  1065. // Calculate date time difference
  1066. if((parseStart.scanedElement >=6) &&
  1067. (parseStop.scanedElement >=6))
  1068. {
  1069. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1070. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1071. tmStart.tm_year = parseStart.year - 1900;
  1072. tmStart.tm_mon = parseStart.month - 1;
  1073. tmStart.tm_mday = parseStart.mday;
  1074. tmStart.tm_hour = parseStart.hour;
  1075. tmStart.tm_min = parseStart.min;
  1076. tmStart.tm_sec = parseStart.sec;
  1077. tmStart.tm_gmtoff = 0;
  1078. tbStart.time = mktime(&tmStart);
  1079. tbStart.timezone = 0;
  1080. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1081. tmStop.tm_year = parseStop.year - 1900;
  1082. tmStop.tm_mon = parseStop.month - 1;
  1083. tmStop.tm_mday = parseStop.mday;
  1084. tmStop.tm_hour = parseStop.hour;
  1085. tmStop.tm_min = parseStop.min;
  1086. tmStop.tm_sec = parseStop.sec;
  1087. tmStop.tm_gmtoff = 0;
  1088. tbStop.time = mktime(&tmStop);
  1089. tbStop.timezone = 0;
  1090. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1091. result = DiffTimebSec(tbStart, tbStop);
  1092. //DEBUG_INFO("getStartStop(): %d\n", result);
  1093. }
  1094. else
  1095. {
  1096. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1097. }
  1098. return result;
  1099. }
  1100. int isOvertNow(uint8_t *start)
  1101. {
  1102. int result = NO;
  1103. struct ParsingResult
  1104. {
  1105. int result;
  1106. int scanedElement;
  1107. int year;
  1108. int month;
  1109. int mday;
  1110. int hour;
  1111. int min;
  1112. int sec;
  1113. int tz_hour;
  1114. int tz_min;
  1115. float minSec;
  1116. }parsingResult;
  1117. struct tm tmStart;
  1118. struct timeb tbStart;
  1119. if(strstr((char*)start, ".") != NULL)
  1120. {
  1121. // Original data with mini second
  1122. if(strstr((char*)start, "Z") != NULL)
  1123. {
  1124. // Original data with Z
  1125. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1126. &parsingResult.year,
  1127. &parsingResult.month,
  1128. &parsingResult.mday,
  1129. &parsingResult.hour,
  1130. &parsingResult.min,
  1131. &parsingResult.sec,
  1132. &parsingResult.minSec);
  1133. }
  1134. else
  1135. {
  1136. // Original data without Z
  1137. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1138. &parsingResult.year,
  1139. &parsingResult.month,
  1140. &parsingResult.mday,
  1141. &parsingResult.hour,
  1142. &parsingResult.min,
  1143. &parsingResult.sec,
  1144. &parsingResult.minSec,
  1145. &parsingResult.tz_hour,
  1146. &parsingResult.tz_min);
  1147. }
  1148. }
  1149. else
  1150. {
  1151. // Original data without mini second
  1152. if(strstr((char*)start, "Z") != NULL)
  1153. {
  1154. // Original data with Z
  1155. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1156. &parsingResult.year,
  1157. &parsingResult.month,
  1158. &parsingResult.mday,
  1159. &parsingResult.hour,
  1160. &parsingResult.min,
  1161. &parsingResult.sec);
  1162. }
  1163. else
  1164. {
  1165. // Original data without Z
  1166. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1167. &parsingResult.year,
  1168. &parsingResult.month,
  1169. &parsingResult.mday,
  1170. &parsingResult.hour,
  1171. &parsingResult.min,
  1172. &parsingResult.sec,
  1173. &parsingResult.tz_hour,
  1174. &parsingResult.tz_min);
  1175. }
  1176. }
  1177. if(parsingResult.scanedElement >= 6)
  1178. {
  1179. tmStart.tm_year = parsingResult.year - 1900;
  1180. tmStart.tm_mon = parsingResult.month - 1;
  1181. tmStart.tm_mday = parsingResult.mday;
  1182. tmStart.tm_hour = parsingResult.hour;
  1183. tmStart.tm_min = parsingResult.min;
  1184. tmStart.tm_sec = parsingResult.sec;
  1185. tmStart.tm_gmtoff = 0;
  1186. tbStart.time = mktime(&tmStart);
  1187. tbStart.timezone = 0;
  1188. tbStart.millitm = 0;
  1189. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1190. if(DiffTimebWithNowSec(tbStart) <= 0)
  1191. result = NO;
  1192. else
  1193. result = YES;
  1194. }
  1195. else
  1196. {
  1197. DEBUG_WARN("Start date parsing error.\n");
  1198. }
  1199. return result;
  1200. }
  1201. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1202. {
  1203. struct ParsingResult
  1204. {
  1205. int result;
  1206. int scanedElement;
  1207. int year;
  1208. int month;
  1209. int mday;
  1210. int hour;
  1211. int min;
  1212. int sec;
  1213. int tz_hour;
  1214. int tz_min;
  1215. float minSec;
  1216. };
  1217. struct ParsingResult parseStart;
  1218. struct ParsingResult parseStop;
  1219. int result = -1;
  1220. struct tm tmStart;
  1221. struct timeb tbStart;
  1222. struct tm tmStop;
  1223. struct timeb tbStop;
  1224. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1225. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1226. // Scan start & stop date time
  1227. if(strstr((char*)start, ".") != NULL)
  1228. {
  1229. // Original data with mini second
  1230. if(strstr((char*)start, "Z") != NULL)
  1231. {
  1232. // Original data with Z
  1233. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1234. &parseStart.year,
  1235. &parseStart.month,
  1236. &parseStart.mday,
  1237. &parseStart.hour,
  1238. &parseStart.min,
  1239. &parseStart.sec,
  1240. &parseStart.minSec);
  1241. }
  1242. else
  1243. {
  1244. // Original data without Z
  1245. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1246. &parseStart.year,
  1247. &parseStart.month,
  1248. &parseStart.mday,
  1249. &parseStart.hour,
  1250. &parseStart.min,
  1251. &parseStart.sec,
  1252. &parseStart.minSec,
  1253. &parseStart.tz_hour,
  1254. &parseStart.tz_min);
  1255. }
  1256. }
  1257. else
  1258. {
  1259. // Original data without mini second
  1260. if(strstr((char*)start, "Z") != NULL)
  1261. {
  1262. // Original data with Z
  1263. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1264. &parseStart.year,
  1265. &parseStart.month,
  1266. &parseStart.mday,
  1267. &parseStart.hour,
  1268. &parseStart.min,
  1269. &parseStart.sec);
  1270. }
  1271. else
  1272. {
  1273. // Original data without Z
  1274. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1275. &parseStart.year,
  1276. &parseStart.month,
  1277. &parseStart.mday,
  1278. &parseStart.hour,
  1279. &parseStart.min,
  1280. &parseStart.sec,
  1281. &parseStart.tz_hour,
  1282. &parseStart.tz_min);
  1283. }
  1284. }
  1285. if(strstr((char*)stop, ".") != NULL)
  1286. {
  1287. // Original data with mini second
  1288. if(strstr((char*)stop, "Z") != NULL)
  1289. {
  1290. // Original data with Z
  1291. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1292. &parseStop.year,
  1293. &parseStop.month,
  1294. &parseStop.mday,
  1295. &parseStop.hour,
  1296. &parseStop.min,
  1297. &parseStop.sec,
  1298. &parseStop.minSec);
  1299. }
  1300. else
  1301. {
  1302. // Original data without Z
  1303. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1304. &parseStop.year,
  1305. &parseStop.month,
  1306. &parseStop.mday,
  1307. &parseStop.hour,
  1308. &parseStop.min,
  1309. &parseStop.sec,
  1310. &parseStop.minSec,
  1311. &parseStop.tz_hour,
  1312. &parseStop.tz_min);
  1313. }
  1314. }
  1315. else
  1316. {
  1317. // Original data without mini second
  1318. if(strstr((char*)stop, "Z") != NULL)
  1319. {
  1320. // Original data with Z
  1321. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1322. &parseStop.year,
  1323. &parseStop.month,
  1324. &parseStop.mday,
  1325. &parseStop.hour,
  1326. &parseStop.min,
  1327. &parseStop.sec);
  1328. }
  1329. else
  1330. {
  1331. // Original data without Z
  1332. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1333. &parseStop.year,
  1334. &parseStop.month,
  1335. &parseStop.mday,
  1336. &parseStop.hour,
  1337. &parseStop.min,
  1338. &parseStop.sec,
  1339. &parseStop.tz_hour,
  1340. &parseStop.tz_min);
  1341. }
  1342. }
  1343. // Calculate date time difference
  1344. if((parseStart.scanedElement >=6) &&
  1345. (parseStop.scanedElement >=6))
  1346. {
  1347. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1348. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1349. tmStart.tm_year = parseStart.year - 1900;
  1350. tmStart.tm_mon = parseStart.month - 1;
  1351. tmStart.tm_mday = parseStart.mday;
  1352. tmStart.tm_hour = parseStart.hour;
  1353. tmStart.tm_min = parseStart.min;
  1354. tmStart.tm_sec = parseStart.sec;
  1355. tmStart.tm_gmtoff = 0;
  1356. tbStart.time = mktime(&tmStart);
  1357. tbStart.timezone = 0;
  1358. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1359. tmStop.tm_year = parseStop.year - 1900;
  1360. tmStop.tm_mon = parseStop.month - 1;
  1361. tmStop.tm_mday = parseStop.mday;
  1362. tmStop.tm_hour = parseStop.hour;
  1363. tmStop.tm_min = parseStop.min;
  1364. tmStop.tm_sec = parseStop.sec;
  1365. tmStop.tm_gmtoff = 0;
  1366. tbStop.time = mktime(&tmStop);
  1367. tbStop.timezone = 0;
  1368. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1369. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1370. //DEBUG_INFO("getStartStop(): %d\n", result);
  1371. }
  1372. else
  1373. {
  1374. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1375. }
  1376. return result;
  1377. }
  1378. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1379. {
  1380. FILE *fp;
  1381. char profileFileName[128];
  1382. char *line = NULL;
  1383. size_t len = 0;
  1384. time_t CurrentTime;
  1385. struct tm *tmComposite;
  1386. struct StructChargingProfile maxProfile;
  1387. struct StructChargingProfile compositeProfile;
  1388. uint8_t limitMax=0;
  1389. int compositePeriodIdx = 0;
  1390. CurrentTime = time(NULL);
  1391. tmComposite=localtime(&CurrentTime);
  1392. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1393. if(isUnitA)
  1394. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1395. else
  1396. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1397. compositeProfile.ChargingSchedule.Duration = durationReq;
  1398. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1399. {
  1400. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1401. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1402. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1403. }
  1404. compositeProfile.ChargingProfileId = 0;
  1405. compositeProfile.StackLevel = 99 ;
  1406. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1407. maxProfile.ChargingProfileId = -1;
  1408. maxProfile.ChargingSchedule.Duration = -1;
  1409. system("rm -f /tmp/*.json");
  1410. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1411. // Search max profile
  1412. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1413. if((access(profileFileName, F_OK))!=-1)
  1414. {
  1415. fp = fopen(profileFileName, "r");
  1416. while(getline(&line, &len, fp) != -1)
  1417. {
  1418. json_object *obj = NULL;
  1419. obj = json_tokener_parse(line);
  1420. if(is_error(obj))
  1421. {
  1422. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1423. }
  1424. else
  1425. {
  1426. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1427. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1428. )
  1429. {
  1430. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1431. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1432. )
  1433. {
  1434. struct tm tmFrom, tmTo;
  1435. struct timeb tbFrom, tbTo;
  1436. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1437. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1438. {
  1439. tmFrom.tm_year -= 1900;
  1440. tmFrom.tm_mon -= 1;
  1441. tbFrom.time = mktime(&tmFrom);
  1442. tmTo.tm_year -= 1900;
  1443. tmTo.tm_mon -= 1;
  1444. tbTo.time = mktime(&tmTo);
  1445. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1446. {
  1447. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1448. {
  1449. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1450. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1451. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1452. }
  1453. if(maxProfile.ChargingProfileId == -1)
  1454. DEBUG_INFO("MaxProfile found.\n");
  1455. else
  1456. DEBUG_INFO("MaxProfile updated.\n");
  1457. // Required item
  1458. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1459. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1460. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1461. if(isUnitA)
  1462. {
  1463. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1464. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1465. {
  1466. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1467. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1468. 3:
  1469. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1470. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1471. }
  1472. }
  1473. else
  1474. {
  1475. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1476. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1477. {
  1478. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1479. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1480. 3:
  1481. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1482. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1483. }
  1484. }
  1485. // Optional item
  1486. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1487. {
  1488. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1489. }
  1490. else
  1491. {
  1492. sprintf((char*)maxProfile.ValidFrom, " ");
  1493. }
  1494. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1495. {
  1496. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1497. }
  1498. else
  1499. {
  1500. sprintf((char*)maxProfile.ValidTo, " ");
  1501. }
  1502. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1503. {
  1504. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1505. }
  1506. else
  1507. {
  1508. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1509. }
  1510. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1511. {
  1512. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1513. }
  1514. else
  1515. {
  1516. maxProfile.TransactionId = -1;
  1517. }
  1518. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1519. {
  1520. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1521. }
  1522. else
  1523. {
  1524. maxProfile.ChargingSchedule.Duration = 86400;
  1525. }
  1526. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1527. {
  1528. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1529. }
  1530. else
  1531. {
  1532. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1533. }
  1534. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1535. {
  1536. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1537. }
  1538. else
  1539. {
  1540. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. else
  1546. {
  1547. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1548. {
  1549. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1552. }
  1553. if(maxProfile.ChargingProfileId == -1)
  1554. DEBUG_INFO("MaxProfile found.\n");
  1555. else
  1556. DEBUG_INFO("MaxProfile updated.\n");
  1557. // Required item
  1558. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1559. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1560. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1561. if(isUnitA)
  1562. {
  1563. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1564. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1565. {
  1566. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1567. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1568. 3:
  1569. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1570. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1571. }
  1572. }
  1573. else
  1574. {
  1575. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1576. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1577. {
  1578. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1579. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1580. 3:
  1581. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1582. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1583. }
  1584. }
  1585. // Optional item
  1586. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1587. {
  1588. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1589. }
  1590. else
  1591. {
  1592. sprintf((char*)maxProfile.ValidFrom, " ");
  1593. }
  1594. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1595. {
  1596. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1597. }
  1598. else
  1599. {
  1600. sprintf((char*)maxProfile.ValidTo, " ");
  1601. }
  1602. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1603. {
  1604. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1605. }
  1606. else
  1607. {
  1608. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1609. }
  1610. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1611. {
  1612. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1613. }
  1614. else
  1615. {
  1616. maxProfile.TransactionId = -1;
  1617. }
  1618. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1619. {
  1620. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1621. }
  1622. else
  1623. {
  1624. maxProfile.ChargingSchedule.Duration = 86400;
  1625. }
  1626. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1627. {
  1628. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1629. }
  1630. else
  1631. {
  1632. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1633. }
  1634. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1635. {
  1636. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1637. }
  1638. else
  1639. {
  1640. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1641. }
  1642. }
  1643. }
  1644. }
  1645. json_object_put(obj);
  1646. }
  1647. fclose(fp);
  1648. /*
  1649. if(maxProfile.ChargingProfileId !=-1)
  1650. {
  1651. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1652. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1653. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1654. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1655. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1656. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1657. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1658. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1659. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1660. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1661. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1662. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1663. {
  1664. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1665. {
  1666. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1667. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1668. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1669. }
  1670. }
  1671. }
  1672. else
  1673. DEBUG_INFO("MaxProfile not found.\n");
  1674. DEBUG_INFO("------------------------------------\n");*/
  1675. }
  1676. if(maxProfile.ChargingProfileId != -1)
  1677. {
  1678. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1679. {
  1680. if(maxProfile.ChargingSchedule.Duration != -1)
  1681. {
  1682. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1683. 0:
  1684. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1685. }
  1686. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1687. {
  1688. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1689. {
  1690. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1691. 0:
  1692. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1693. if(idxPeriod > 0)
  1694. {
  1695. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1696. {
  1697. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1698. }
  1699. }
  1700. }
  1701. }
  1702. }
  1703. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1704. {
  1705. if(maxProfile.ChargingSchedule.Duration != -1)
  1706. {
  1707. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1708. }
  1709. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1710. {
  1711. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1712. {
  1713. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1714. if(idxPeriod > 0)
  1715. {
  1716. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1717. {
  1718. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1719. }
  1720. }
  1721. }
  1722. }
  1723. }
  1724. else
  1725. {
  1726. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1727. {
  1728. if(maxProfile.ChargingSchedule.Duration != -1)
  1729. {
  1730. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1731. 0:
  1732. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1733. }
  1734. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1735. {
  1736. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1737. {
  1738. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1739. 0:
  1740. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1741. if(idxPeriod > 0)
  1742. {
  1743. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1744. {
  1745. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1746. }
  1747. }
  1748. }
  1749. }
  1750. }
  1751. else
  1752. {
  1753. if(maxProfile.ChargingSchedule.Duration != -1)
  1754. {
  1755. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1756. 0:
  1757. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1758. }
  1759. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1760. {
  1761. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1762. {
  1763. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1764. 0:
  1765. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1766. if(idxPeriod > 0)
  1767. {
  1768. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1769. {
  1770. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1771. }
  1772. }
  1773. }
  1774. }
  1775. }
  1776. }
  1777. /*
  1778. DEBUG_INFO("MaxProfile after align.\n");
  1779. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1780. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1781. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1782. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1783. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1784. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1785. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1786. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1787. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1788. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1789. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1790. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1791. {
  1792. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1793. {
  1794. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1795. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1796. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1797. }
  1798. }
  1799. DEBUG_INFO("------------------------------------\n");*/
  1800. }
  1801. // Find each profile period quantity
  1802. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1803. {
  1804. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1805. limitMax = idx+1;
  1806. }
  1807. if(maxProfile.ChargingProfileId != -1)
  1808. {
  1809. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1810. {
  1811. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1812. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1813. (maxProfile.ChargingSchedule.Duration > 0))
  1814. {
  1815. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1816. {
  1817. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1818. compositePeriodIdx++;
  1819. }
  1820. else
  1821. {
  1822. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1823. }
  1824. }
  1825. }
  1826. }
  1827. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1828. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1829. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1830. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1831. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1832. {
  1833. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1834. {
  1835. compositeProfile.ChargingProfileId = 1;
  1836. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1837. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1838. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1839. }
  1840. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1841. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1842. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1843. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1844. }
  1845. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1846. if(line)
  1847. free(line);
  1848. }
  1849. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1850. {
  1851. FILE *fp;
  1852. char profileFileName[128];
  1853. char *line = NULL;
  1854. size_t len = 0;
  1855. time_t CurrentTime;
  1856. struct tm *tmComposite;
  1857. struct StructChargingProfile maxProfile;
  1858. struct StructChargingProfile defaultTxProfile;
  1859. struct StructChargingProfile txProfile;
  1860. struct StructChargingProfile compositeProfile;
  1861. struct StructChargingSchedulePeriod tmpPeriod;
  1862. uint8_t limitMax=0;
  1863. uint8_t limitDef=0;
  1864. uint8_t limitTx=0;
  1865. int compositePeriodIdx = 0;
  1866. CurrentTime = time(NULL);
  1867. tmComposite=localtime(&CurrentTime);
  1868. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1869. if(isUnitA)
  1870. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1871. else
  1872. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1873. compositeProfile.ChargingSchedule.Duration = durationReq;
  1874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1875. {
  1876. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1877. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1878. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1879. }
  1880. compositeProfile.ChargingProfileId = 0;
  1881. compositeProfile.StackLevel = 99 ;
  1882. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1883. maxProfile.ChargingProfileId = -1;
  1884. defaultTxProfile.ChargingProfileId = -1;
  1885. txProfile.ChargingProfileId = -1;
  1886. maxProfile.ChargingSchedule.Duration = -1;
  1887. defaultTxProfile.ChargingSchedule.Duration = -1;
  1888. txProfile.ChargingSchedule.Duration = -1;
  1889. system("rm -f /tmp/*.json");
  1890. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1891. /*
  1892. * Search valid charging profile
  1893. */
  1894. //DEBUG_INFO("====================================\n");
  1895. // Search tx profile
  1896. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1897. if((access(profileFileName, F_OK))!=-1)
  1898. {
  1899. fp = fopen(profileFileName, "r");
  1900. while(getline(&line, &len, fp) != -1)
  1901. {
  1902. json_object *obj = NULL;
  1903. obj = json_tokener_parse(line);
  1904. if(is_error(obj))
  1905. {
  1906. DEBUG_ERROR("Parse txProfile from file error.\n");
  1907. }
  1908. else
  1909. {
  1910. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1911. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1912. )
  1913. {
  1914. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1915. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1916. )
  1917. {
  1918. struct tm tmFrom, tmTo;
  1919. struct timeb tbFrom, tbTo;
  1920. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1921. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1922. {
  1923. tmFrom.tm_year -= 1900;
  1924. tmFrom.tm_mon -= 1;
  1925. tbFrom.time = mktime(&tmFrom);
  1926. tmTo.tm_year -= 1900;
  1927. tmTo.tm_mon -= 1;
  1928. tbTo.time = mktime(&tmTo);
  1929. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1930. {
  1931. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1932. {
  1933. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1934. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1935. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1936. }
  1937. if(txProfile.ChargingProfileId == -1)
  1938. DEBUG_INFO("TxProfile found.\n");
  1939. else
  1940. DEBUG_INFO("TxProfile updated.\n");
  1941. // Required item
  1942. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1943. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1944. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1945. if(isUnitA)
  1946. {
  1947. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1948. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1949. {
  1950. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1951. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1952. 3:
  1953. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1954. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1955. }
  1956. }
  1957. else
  1958. {
  1959. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1960. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1961. {
  1962. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1963. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1964. 3:
  1965. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1966. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1967. }
  1968. }
  1969. // Optional item
  1970. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1971. {
  1972. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1973. }
  1974. else
  1975. {
  1976. sprintf((char*)txProfile.ValidFrom, " ");
  1977. }
  1978. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1979. {
  1980. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1981. }
  1982. else
  1983. {
  1984. sprintf((char*)txProfile.ValidTo, " ");
  1985. }
  1986. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1987. {
  1988. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1989. }
  1990. else
  1991. {
  1992. sprintf((char*)txProfile.RecurrencyKind, " ");
  1993. }
  1994. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1995. {
  1996. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1997. }
  1998. else
  1999. {
  2000. txProfile.TransactionId = -1;
  2001. }
  2002. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2003. {
  2004. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2005. }
  2006. else
  2007. {
  2008. txProfile.ChargingSchedule.Duration = 86400;
  2009. }
  2010. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2011. {
  2012. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2013. }
  2014. else
  2015. {
  2016. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2017. }
  2018. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2019. {
  2020. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2021. }
  2022. else
  2023. {
  2024. txProfile.ChargingSchedule.MinChargingRate = -1;
  2025. }
  2026. }
  2027. }
  2028. }
  2029. else
  2030. {
  2031. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2032. {
  2033. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2034. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2035. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2036. }
  2037. if(txProfile.ChargingProfileId == -1)
  2038. DEBUG_INFO("TxProfile found.\n");
  2039. else
  2040. DEBUG_INFO("TxProfile updated.\n");
  2041. // Required item
  2042. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2043. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2044. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2045. if(isUnitA)
  2046. {
  2047. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2048. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2049. {
  2050. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2051. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2052. 3:
  2053. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2054. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2055. }
  2056. }
  2057. else
  2058. {
  2059. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2060. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2061. {
  2062. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2063. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2064. 3:
  2065. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2066. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2067. }
  2068. }
  2069. // Optional item
  2070. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2071. {
  2072. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2073. }
  2074. else
  2075. {
  2076. sprintf((char*)txProfile.ValidFrom, " ");
  2077. }
  2078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2079. {
  2080. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2081. }
  2082. else
  2083. {
  2084. sprintf((char*)txProfile.ValidTo, " ");
  2085. }
  2086. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2087. {
  2088. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2089. }
  2090. else
  2091. {
  2092. sprintf((char*)txProfile.RecurrencyKind, " ");
  2093. }
  2094. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2095. {
  2096. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2097. }
  2098. else
  2099. {
  2100. txProfile.TransactionId = -1;
  2101. }
  2102. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2103. {
  2104. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2105. }
  2106. else
  2107. {
  2108. txProfile.ChargingSchedule.Duration = 86400;
  2109. }
  2110. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2111. {
  2112. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2113. }
  2114. else
  2115. {
  2116. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2117. }
  2118. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2119. {
  2120. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2121. }
  2122. else
  2123. {
  2124. txProfile.ChargingSchedule.MinChargingRate = -1;
  2125. }
  2126. }
  2127. }
  2128. }
  2129. json_object_put(obj);
  2130. }
  2131. fclose(fp);
  2132. /*
  2133. if(txProfile.ChargingProfileId != -1)
  2134. {
  2135. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2136. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2137. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2138. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2139. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2140. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2141. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2142. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2143. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2144. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2145. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2146. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2147. {
  2148. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2149. {
  2150. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2151. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2152. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2153. }
  2154. }
  2155. }
  2156. else
  2157. DEBUG_INFO("TxProfile not found.\n");*/
  2158. }
  2159. // Search default tx profile
  2160. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2161. if((access(profileFileName, F_OK))==-1)
  2162. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2163. if((access(profileFileName, F_OK))!=-1)
  2164. {
  2165. fp = fopen(profileFileName, "r");
  2166. while(getline(&line, &len, fp) != -1)
  2167. {
  2168. json_object *obj = NULL;
  2169. obj = json_tokener_parse(line);
  2170. if(is_error(obj))
  2171. {
  2172. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2173. }
  2174. else
  2175. {
  2176. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2177. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2178. )
  2179. {
  2180. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2181. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2182. )
  2183. {
  2184. struct tm tmFrom, tmTo;
  2185. struct timeb tbFrom, tbTo;
  2186. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2187. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2188. {
  2189. tmFrom.tm_year -= 1900;
  2190. tmFrom.tm_mon -= 1;
  2191. tbFrom.time = mktime(&tmFrom);
  2192. tmTo.tm_year -= 1900;
  2193. tmTo.tm_mon -= 1;
  2194. tbTo.time = mktime(&tmTo);
  2195. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2196. {
  2197. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2198. {
  2199. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2200. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2201. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2202. }
  2203. if(defaultTxProfile.ChargingProfileId == -1)
  2204. DEBUG_INFO("TxDefaultProfile found.\n");
  2205. else
  2206. DEBUG_INFO("TxDefaultProfile updated.\n");
  2207. // Required item
  2208. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2209. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2210. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2211. if(isUnitA)
  2212. {
  2213. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2214. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2215. {
  2216. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2217. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2218. 3:
  2219. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2220. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2221. }
  2222. }
  2223. else
  2224. {
  2225. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2226. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2227. {
  2228. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2229. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2230. 3:
  2231. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2232. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2233. }
  2234. }
  2235. // Optional item
  2236. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2237. {
  2238. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2239. }
  2240. else
  2241. {
  2242. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2243. }
  2244. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2245. {
  2246. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2247. }
  2248. else
  2249. {
  2250. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2251. }
  2252. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2253. {
  2254. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2255. }
  2256. else
  2257. {
  2258. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2259. }
  2260. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2261. {
  2262. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2263. }
  2264. else
  2265. {
  2266. defaultTxProfile.TransactionId = -1;
  2267. }
  2268. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2269. {
  2270. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2271. }
  2272. else
  2273. {
  2274. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2275. }
  2276. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2277. {
  2278. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2279. }
  2280. else
  2281. {
  2282. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2283. }
  2284. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2285. {
  2286. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2287. }
  2288. else
  2289. {
  2290. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2291. }
  2292. }
  2293. }
  2294. }
  2295. else
  2296. {
  2297. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2298. {
  2299. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2300. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2301. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2302. }
  2303. if(defaultTxProfile.ChargingProfileId == -1)
  2304. DEBUG_INFO("TxDefaultProfile found.\n");
  2305. else
  2306. DEBUG_INFO("TxDefaultProfile updated.\n");
  2307. // Required item
  2308. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2309. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2310. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2311. if(isUnitA)
  2312. {
  2313. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2314. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2315. {
  2316. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2317. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2318. 3:
  2319. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2320. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2321. }
  2322. }
  2323. else
  2324. {
  2325. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2326. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2327. {
  2328. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2329. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2330. 3:
  2331. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2332. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2333. }
  2334. }
  2335. // Optional item
  2336. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2337. {
  2338. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2339. }
  2340. else
  2341. {
  2342. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2343. }
  2344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2345. {
  2346. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2347. }
  2348. else
  2349. {
  2350. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2351. }
  2352. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2353. {
  2354. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2355. }
  2356. else
  2357. {
  2358. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2359. }
  2360. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2361. {
  2362. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2363. }
  2364. else
  2365. {
  2366. defaultTxProfile.TransactionId = -1;
  2367. }
  2368. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2369. {
  2370. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2371. }
  2372. else
  2373. {
  2374. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2375. }
  2376. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2377. {
  2378. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2379. }
  2380. else
  2381. {
  2382. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2383. }
  2384. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2385. {
  2386. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2387. }
  2388. else
  2389. {
  2390. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2391. }
  2392. }
  2393. }
  2394. }
  2395. json_object_put(obj);
  2396. }
  2397. fclose(fp);
  2398. /*
  2399. if(defaultTxProfile.ChargingProfileId != -1)
  2400. {
  2401. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2402. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2403. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2404. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2405. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2406. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2407. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2408. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2409. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2410. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2411. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2412. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2413. {
  2414. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2415. {
  2416. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2417. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2418. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2419. }
  2420. }
  2421. }
  2422. else
  2423. DEBUG_INFO("TxDefaultProfile not found.\n");
  2424. DEBUG_INFO("------------------------------------\n");*/
  2425. }
  2426. // Search max profile
  2427. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2428. if((access(profileFileName, F_OK))!=-1)
  2429. {
  2430. fp = fopen(profileFileName, "r");
  2431. while(getline(&line, &len, fp) != -1)
  2432. {
  2433. json_object *obj = NULL;
  2434. obj = json_tokener_parse(line);
  2435. if(is_error(obj))
  2436. {
  2437. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2438. }
  2439. else
  2440. {
  2441. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2442. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2443. )
  2444. {
  2445. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2446. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2447. )
  2448. {
  2449. struct tm tmFrom, tmTo;
  2450. struct timeb tbFrom, tbTo;
  2451. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2452. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2453. {
  2454. tmFrom.tm_year -= 1900;
  2455. tmFrom.tm_mon -= 1;
  2456. tbFrom.time = mktime(&tmFrom);
  2457. tmTo.tm_year -= 1900;
  2458. tmTo.tm_mon -= 1;
  2459. tbTo.time = mktime(&tmTo);
  2460. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2461. {
  2462. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2463. {
  2464. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2465. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2466. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2467. }
  2468. if(maxProfile.ChargingProfileId == -1)
  2469. DEBUG_INFO("MaxProfile found.\n");
  2470. else
  2471. DEBUG_INFO("MaxProfile updated.\n");
  2472. // Required item
  2473. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2474. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2475. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2476. if(isUnitA)
  2477. {
  2478. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2479. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2480. {
  2481. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2482. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2483. 3:
  2484. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2485. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2486. }
  2487. }
  2488. else
  2489. {
  2490. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2491. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2492. {
  2493. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2494. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2495. 3:
  2496. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2497. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2498. }
  2499. }
  2500. // Optional item
  2501. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2502. {
  2503. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2504. }
  2505. else
  2506. {
  2507. sprintf((char*)maxProfile.ValidFrom, " ");
  2508. }
  2509. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2510. {
  2511. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2512. }
  2513. else
  2514. {
  2515. sprintf((char*)maxProfile.ValidTo, " ");
  2516. }
  2517. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2518. {
  2519. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2520. }
  2521. else
  2522. {
  2523. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2524. }
  2525. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2526. {
  2527. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2528. }
  2529. else
  2530. {
  2531. maxProfile.TransactionId = -1;
  2532. }
  2533. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2534. {
  2535. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2536. }
  2537. else
  2538. {
  2539. maxProfile.ChargingSchedule.Duration = 86400;
  2540. }
  2541. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2542. {
  2543. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2544. }
  2545. else
  2546. {
  2547. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2548. }
  2549. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2550. {
  2551. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2552. }
  2553. else
  2554. {
  2555. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2556. }
  2557. }
  2558. }
  2559. }
  2560. else
  2561. {
  2562. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2563. {
  2564. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2565. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2566. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2567. }
  2568. if(maxProfile.ChargingProfileId == -1)
  2569. DEBUG_INFO("MaxProfile found.\n");
  2570. else
  2571. DEBUG_INFO("MaxProfile updated.\n");
  2572. // Required item
  2573. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2574. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2575. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2576. if(isUnitA)
  2577. {
  2578. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2579. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2580. {
  2581. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2582. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2583. 3:
  2584. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2585. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2586. }
  2587. }
  2588. else
  2589. {
  2590. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2591. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2592. {
  2593. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2594. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2595. 3:
  2596. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2597. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2598. }
  2599. }
  2600. // Optional item
  2601. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2602. {
  2603. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2604. }
  2605. else
  2606. {
  2607. sprintf((char*)maxProfile.ValidFrom, " ");
  2608. }
  2609. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2610. {
  2611. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2612. }
  2613. else
  2614. {
  2615. sprintf((char*)maxProfile.ValidTo, " ");
  2616. }
  2617. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2618. {
  2619. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2620. }
  2621. else
  2622. {
  2623. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2624. }
  2625. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2626. {
  2627. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2628. }
  2629. else
  2630. {
  2631. maxProfile.TransactionId = -1;
  2632. }
  2633. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2634. {
  2635. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2636. }
  2637. else
  2638. {
  2639. maxProfile.ChargingSchedule.Duration = 86400;
  2640. }
  2641. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2642. {
  2643. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2644. }
  2645. else
  2646. {
  2647. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2648. }
  2649. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2650. {
  2651. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2652. }
  2653. else
  2654. {
  2655. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2656. }
  2657. }
  2658. }
  2659. }
  2660. json_object_put(obj);
  2661. }
  2662. fclose(fp);
  2663. /*
  2664. if(maxProfile.ChargingProfileId !=-1)
  2665. {
  2666. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2667. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2668. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2669. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2670. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2671. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2672. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2673. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2674. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2675. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2676. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2677. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2678. {
  2679. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2680. {
  2681. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2682. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2683. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2684. }
  2685. }
  2686. }
  2687. else
  2688. DEBUG_INFO("MaxProfile not found.\n");
  2689. DEBUG_INFO("------------------------------------\n");*/
  2690. }
  2691. /*
  2692. * Align found profile start schedule & periods
  2693. */
  2694. //DEBUG_INFO("====================================\n");
  2695. /*
  2696. // For local test usage, force modify found profile start schedule info
  2697. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  2698. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  2699. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  2700. */
  2701. if(txProfile.ChargingProfileId != -1)
  2702. {
  2703. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2704. {
  2705. if(txProfile.ChargingSchedule.Duration != -1)
  2706. {
  2707. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2708. 0:
  2709. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2710. }
  2711. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2712. {
  2713. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2714. {
  2715. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2716. 0:
  2717. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2718. if(idxPeriod > 0)
  2719. {
  2720. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2721. {
  2722. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2723. }
  2724. }
  2725. }
  2726. }
  2727. }
  2728. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2729. {
  2730. if(txProfile.ChargingSchedule.Duration != -1)
  2731. {
  2732. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2733. 0:
  2734. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2735. }
  2736. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2737. {
  2738. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2739. {
  2740. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2741. 0:
  2742. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2743. if(idxPeriod > 0)
  2744. {
  2745. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2746. {
  2747. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2748. }
  2749. }
  2750. }
  2751. }
  2752. }
  2753. else
  2754. {
  2755. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2756. {
  2757. if(txProfile.ChargingSchedule.Duration != -1)
  2758. {
  2759. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2760. 0:
  2761. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2762. }
  2763. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2764. {
  2765. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2766. {
  2767. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2768. 0:
  2769. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2770. if(idxPeriod > 0)
  2771. {
  2772. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2773. {
  2774. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2775. }
  2776. }
  2777. }
  2778. }
  2779. }
  2780. else
  2781. {
  2782. if(txProfile.ChargingSchedule.Duration != -1)
  2783. {
  2784. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2785. 0:
  2786. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2787. }
  2788. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2789. {
  2790. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2791. {
  2792. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2793. 0:
  2794. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2795. if(idxPeriod > 0)
  2796. {
  2797. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2798. {
  2799. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2800. }
  2801. }
  2802. }
  2803. }
  2804. }
  2805. }
  2806. /*
  2807. DEBUG_INFO("txProfile after align.\n");
  2808. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2809. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2810. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2811. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2812. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2813. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2814. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2815. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2816. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2817. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2818. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2819. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2820. {
  2821. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2822. {
  2823. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2824. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2825. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2826. }
  2827. }*/
  2828. }
  2829. if(defaultTxProfile.ChargingProfileId != -1)
  2830. {
  2831. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2832. {
  2833. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2834. {
  2835. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2836. 0:
  2837. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2838. }
  2839. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2840. {
  2841. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2842. {
  2843. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2844. 0:
  2845. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2846. if(idxPeriod > 0)
  2847. {
  2848. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2849. {
  2850. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2857. {
  2858. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2859. {
  2860. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2861. 0:
  2862. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2863. }
  2864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2865. {
  2866. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2867. {
  2868. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2869. 0:
  2870. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2871. if(idxPeriod > 0)
  2872. {
  2873. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2874. {
  2875. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. else
  2882. {
  2883. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2884. {
  2885. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2886. {
  2887. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2888. 0:
  2889. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2890. }
  2891. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2892. {
  2893. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2894. {
  2895. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2896. 0:
  2897. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2898. if(idxPeriod > 0)
  2899. {
  2900. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2901. {
  2902. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2903. }
  2904. }
  2905. }
  2906. }
  2907. }
  2908. else
  2909. {
  2910. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2911. {
  2912. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2913. 0:
  2914. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2915. }
  2916. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2917. {
  2918. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2919. {
  2920. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2921. 0:
  2922. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2923. if(idxPeriod > 0)
  2924. {
  2925. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2926. {
  2927. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2928. }
  2929. }
  2930. }
  2931. }
  2932. }
  2933. }
  2934. /*
  2935. DEBUG_INFO("defaultTxProfile after align.\n");
  2936. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2937. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2938. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2939. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2940. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2941. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2942. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2943. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2944. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2945. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2946. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2947. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2948. {
  2949. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2950. {
  2951. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2952. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2953. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2954. }
  2955. }
  2956. DEBUG_INFO("------------------------------------\n");*/
  2957. }
  2958. if(maxProfile.ChargingProfileId != -1)
  2959. {
  2960. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2961. {
  2962. if(maxProfile.ChargingSchedule.Duration != -1)
  2963. {
  2964. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2965. 0:
  2966. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2967. }
  2968. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2969. {
  2970. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2971. {
  2972. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2973. 0:
  2974. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2975. if(idxPeriod > 0)
  2976. {
  2977. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2978. {
  2979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2980. }
  2981. }
  2982. }
  2983. }
  2984. }
  2985. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2986. {
  2987. if(maxProfile.ChargingSchedule.Duration != -1)
  2988. {
  2989. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2990. 0:
  2991. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2992. }
  2993. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2994. {
  2995. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2996. {
  2997. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2998. 0:
  2999. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3000. if(idxPeriod > 0)
  3001. {
  3002. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3003. {
  3004. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3005. }
  3006. }
  3007. }
  3008. }
  3009. }
  3010. else
  3011. {
  3012. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3013. {
  3014. if(maxProfile.ChargingSchedule.Duration != -1)
  3015. {
  3016. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3017. 0:
  3018. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3019. }
  3020. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3021. {
  3022. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3023. {
  3024. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3025. 0:
  3026. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3027. if(idxPeriod > 0)
  3028. {
  3029. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3030. {
  3031. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3032. }
  3033. }
  3034. }
  3035. }
  3036. }
  3037. else
  3038. {
  3039. if(maxProfile.ChargingSchedule.Duration != -1)
  3040. {
  3041. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3042. 0:
  3043. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3044. }
  3045. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3046. {
  3047. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3048. {
  3049. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3050. 0:
  3051. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3052. if(idxPeriod > 0)
  3053. {
  3054. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3055. {
  3056. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3057. }
  3058. }
  3059. }
  3060. }
  3061. }
  3062. }
  3063. /*
  3064. DEBUG_INFO("MaxProfile after align.\n");
  3065. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3066. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3067. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3068. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3069. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3070. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3071. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3072. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3073. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3074. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3075. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3076. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3077. {
  3078. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3079. {
  3080. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3081. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3082. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3083. }
  3084. }
  3085. DEBUG_INFO("------------------------------------\n");*/
  3086. }
  3087. /*
  3088. * Merge to conposite schedule
  3089. */
  3090. //DEBUG_INFO("====================================\n");
  3091. // Find each profile period quantity
  3092. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3093. {
  3094. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3095. limitMax = idx+1;
  3096. }
  3097. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3098. {
  3099. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3100. limitDef = idx+1;
  3101. }
  3102. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3103. {
  3104. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3105. limitTx = idx+1;
  3106. }
  3107. // TxProfile found, composite schedule based on it
  3108. if(txProfile.ChargingProfileId != -1)
  3109. {
  3110. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3111. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3112. {
  3113. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3114. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3115. (txProfile.ChargingSchedule.Duration > 0))
  3116. {
  3117. if(maxProfile.ChargingProfileId != -1)
  3118. {
  3119. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3120. {
  3121. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3122. {
  3123. if((maxProfile.ChargingSchedule.Duration > 0))
  3124. {
  3125. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3126. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3127. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3128. }
  3129. else
  3130. {
  3131. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3132. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3133. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3134. }
  3135. }
  3136. if(idxMaxPeriod == (limitMax-1))
  3137. {
  3138. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3139. {
  3140. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3141. {
  3142. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3143. compositePeriodIdx++;
  3144. }
  3145. else
  3146. {
  3147. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3148. }
  3149. }
  3150. }
  3151. }
  3152. }
  3153. else
  3154. {
  3155. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3156. {
  3157. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3158. compositePeriodIdx++;
  3159. }
  3160. else
  3161. {
  3162. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3163. }
  3164. }
  3165. }
  3166. if(idxTxPeriod == (limitTx-1))
  3167. {
  3168. if(defaultTxProfile.ChargingProfileId != -1)
  3169. {
  3170. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3171. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3172. {
  3173. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3174. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3175. (defaultTxProfile.ChargingSchedule.Duration>0))
  3176. {
  3177. if(maxProfile.ChargingProfileId != -1)
  3178. {
  3179. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3180. {
  3181. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3182. {
  3183. if((maxProfile.ChargingSchedule.Duration > 0))
  3184. {
  3185. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3186. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3187. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3188. }
  3189. else
  3190. {
  3191. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3192. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3193. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3194. }
  3195. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3196. {
  3197. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3198. {
  3199. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3200. compositePeriodIdx++;
  3201. }
  3202. else
  3203. {
  3204. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3205. }
  3206. }
  3207. // Delete duplicate period
  3208. if(compositePeriodIdx > 1)
  3209. {
  3210. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3211. {
  3212. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3213. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3214. compositePeriodIdx -= 1;
  3215. }
  3216. }
  3217. }
  3218. else
  3219. {
  3220. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3221. {
  3222. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3223. compositePeriodIdx++;
  3224. }
  3225. else
  3226. {
  3227. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3228. }
  3229. break;
  3230. }
  3231. }
  3232. }
  3233. else
  3234. {
  3235. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3236. {
  3237. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3238. compositePeriodIdx++;
  3239. }
  3240. else
  3241. {
  3242. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3243. }
  3244. }
  3245. }
  3246. }
  3247. }
  3248. }
  3249. }
  3250. }
  3251. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3252. else if(defaultTxProfile.ChargingProfileId != -1)
  3253. {
  3254. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3255. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3256. {
  3257. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3258. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3259. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3260. {
  3261. if(maxProfile.ChargingProfileId != -1)
  3262. {
  3263. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3264. {
  3265. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3266. {
  3267. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3268. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3269. if((maxProfile.ChargingSchedule.Duration > 0))
  3270. {
  3271. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3272. }
  3273. else
  3274. {
  3275. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3276. }
  3277. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3278. {
  3279. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3280. {
  3281. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3282. compositePeriodIdx++;
  3283. }
  3284. else
  3285. {
  3286. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3287. }
  3288. }
  3289. // Delete duplicate period
  3290. if(compositePeriodIdx > 1)
  3291. {
  3292. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3293. {
  3294. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3295. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3296. compositePeriodIdx -= 1;
  3297. }
  3298. }
  3299. }
  3300. else
  3301. {
  3302. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3303. {
  3304. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3305. compositePeriodIdx++;
  3306. }
  3307. else
  3308. {
  3309. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3310. }
  3311. break;
  3312. }
  3313. }
  3314. }
  3315. else
  3316. {
  3317. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3318. {
  3319. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3320. compositePeriodIdx++;
  3321. }
  3322. else
  3323. {
  3324. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3325. }
  3326. }
  3327. }
  3328. }
  3329. }
  3330. // Fill other period by MaxProfile
  3331. if(maxProfile.ChargingProfileId != -1)
  3332. {
  3333. if(compositePeriodIdx==0)
  3334. {
  3335. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3336. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3337. {
  3338. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3339. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3340. (maxProfile.ChargingSchedule.Duration > 0))
  3341. {
  3342. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3343. {
  3344. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3345. compositePeriodIdx++;
  3346. }
  3347. else
  3348. {
  3349. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3350. }
  3351. }
  3352. }
  3353. }
  3354. else
  3355. {
  3356. int lastCompositePeriodIdx = compositePeriodIdx;
  3357. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3358. {
  3359. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3360. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3361. (maxProfile.ChargingSchedule.Duration > 0))
  3362. {
  3363. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3364. {
  3365. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3366. {
  3367. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3368. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3369. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3370. }
  3371. else
  3372. {
  3373. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3374. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3375. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3376. }
  3377. }
  3378. if(tmpPeriod.Limit != -1)
  3379. {
  3380. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3381. {
  3382. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3383. {
  3384. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3385. compositePeriodIdx++;
  3386. }
  3387. else
  3388. {
  3389. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3390. }
  3391. }
  3392. // Delete duplicate period
  3393. if(compositePeriodIdx > 1)
  3394. {
  3395. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3396. {
  3397. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3398. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3399. compositePeriodIdx -= 1;
  3400. }
  3401. }
  3402. }
  3403. }
  3404. }
  3405. }
  3406. }
  3407. compositeProfile.ChargingSchedule.Duration = durationReq;
  3408. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3409. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3410. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3411. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3412. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3413. {
  3414. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3415. {
  3416. compositeProfile.ChargingProfileId = 1;
  3417. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3418. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3419. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3420. }
  3421. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3422. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3423. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3424. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3425. }
  3426. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3427. if(line)
  3428. free(line);
  3429. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3430. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3431. }
  3432. //==========================================
  3433. // Init all share memory
  3434. //==========================================
  3435. int InitShareMemory()
  3436. {
  3437. int result = PASS;
  3438. int MeterSMId;
  3439. //creat ShmSysConfigAndInfo
  3440. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3441. {
  3442. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3443. result = FAIL;
  3444. }
  3445. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3446. {
  3447. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3448. result = FAIL;
  3449. }
  3450. else
  3451. {}
  3452. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3453. {
  3454. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3455. result = FAIL;
  3456. }
  3457. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3458. {
  3459. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3460. result = FAIL;
  3461. }
  3462. else
  3463. {}
  3464. //creat ShmPsuData
  3465. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3466. {
  3467. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3468. result = FAIL;
  3469. }
  3470. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3471. {
  3472. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3473. result = FAIL;
  3474. }
  3475. else
  3476. {}
  3477. //link ShmOCPP16Data
  3478. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3479. {
  3480. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3481. result = FAIL;
  3482. }
  3483. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3484. {
  3485. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3486. result = FAIL;
  3487. }
  3488. else
  3489. {}
  3490. //creat ShmOCPP16DataPH
  3491. if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3492. {
  3493. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3494. result = FAIL;
  3495. }
  3496. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3497. {
  3498. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3499. result = FAIL;
  3500. }
  3501. else
  3502. {}
  3503. /****************************** For Initial Settings************************************************/
  3504. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3505. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3506. // allocate Configuration memory address
  3507. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3508. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3509. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3510. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3511. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3512. //offline MeterValue Interval
  3513. TempMeterValueInterval = 0;
  3514. return result;
  3515. }
  3516. int ProcessShareMemory()
  3517. {
  3518. int result = PASS;
  3519. if(InitShareMemory() == FAIL)
  3520. {
  3521. DEBUG_ERROR("InitShareMemory NG\n");
  3522. if(ShmStatusCodeData!=NULL)
  3523. {
  3524. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3525. }
  3526. result = FAIL;
  3527. }
  3528. // Model name parsing
  3529. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3530. {
  3531. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3532. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3533. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3534. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3535. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3536. ) // 'D' means DC
  3537. {
  3538. // DO series
  3539. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3540. {
  3541. gunTotalNumber += 1;
  3542. gunType[gun_index] = GUN_TYPE_DO;
  3543. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3544. {
  3545. case Gun_Type_Chademo:
  3546. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3547. break;
  3548. case Gun_Type_CCS_2:
  3549. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3550. break;
  3551. case Gun_Type_GB:
  3552. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3553. break;
  3554. case Gun_Type_AC:
  3555. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3556. break;
  3557. default:
  3558. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3559. break;
  3560. }
  3561. }
  3562. }
  3563. else
  3564. {
  3565. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3566. {
  3567. gunTotalNumber += 1;
  3568. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3569. {
  3570. case Gun_Type_Chademo:
  3571. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3572. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3573. break;
  3574. case Gun_Type_CCS_2:
  3575. gunType[gun_index] = GUN_TYPE_CCS;
  3576. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3577. break;
  3578. case Gun_Type_GB:
  3579. gunType[gun_index] = GUN_TYPE_GBT;
  3580. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3581. break;
  3582. case Gun_Type_AC:
  3583. gunType[gun_index] = GUN_TYPE_AC;
  3584. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3585. break;
  3586. default:
  3587. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3588. break;
  3589. }
  3590. }
  3591. }
  3592. }
  3593. else
  3594. {
  3595. DEBUG_ERROR("Model name parsing fail.\n");
  3596. result = FAIL;
  3597. }
  3598. if(result != PASS)sleep(5);
  3599. return result;
  3600. }
  3601. void checkRemoteStart(uint8_t connectorIdInt)
  3602. {
  3603. uint8_t tempIndex;
  3604. int result = PASS;
  3605. char cmdBuf[512];
  3606. //check Transaction active
  3607. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3608. {
  3609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3610. {
  3611. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3612. }
  3613. else
  3614. {
  3615. tempIndex = connectorIdInt -1;
  3616. }
  3617. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3618. {
  3619. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3620. {
  3621. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3622. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3623. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3624. {
  3625. //Reserved
  3626. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3627. }
  3628. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3629. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3630. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3631. {
  3632. //Reserved
  3633. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3634. result = FAIL;
  3635. goto end;
  3636. }
  3637. else
  3638. {
  3639. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3640. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3641. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3642. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3643. {
  3644. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3645. result = FAIL;
  3646. goto end;
  3647. }
  3648. }//END FOR ELSE
  3649. }
  3650. }// END FOR CHAdeMO_QUANTITY
  3651. }
  3652. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3653. {
  3654. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3655. {
  3656. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3657. }
  3658. else
  3659. {
  3660. tempIndex = connectorIdInt -1;
  3661. }
  3662. for (int index = 0; index < CCS_QUANTITY; index++)
  3663. {
  3664. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3665. {
  3666. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3667. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3668. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3669. {
  3670. //Reserved
  3671. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3672. }
  3673. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3674. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3675. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3676. {
  3677. //Reserved
  3678. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3679. result = FAIL;
  3680. goto end;
  3681. }
  3682. else
  3683. {
  3684. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3685. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3686. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3687. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3688. {
  3689. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3690. result = FAIL;
  3691. goto end;
  3692. }
  3693. }// END FOR ELSE
  3694. }
  3695. }// END FOR CCS_QUANTITY
  3696. }
  3697. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3698. {
  3699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3700. {
  3701. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3702. }
  3703. else
  3704. {
  3705. tempIndex = connectorIdInt -1;
  3706. }
  3707. for (int index = 0; index < GB_QUANTITY; index++)
  3708. {
  3709. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3710. {
  3711. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3712. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3713. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3714. {
  3715. //Reserved
  3716. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3717. }
  3718. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3719. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3720. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3721. {
  3722. //Reserved
  3723. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3724. result = FAIL;
  3725. goto end;
  3726. }
  3727. else
  3728. {
  3729. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3730. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3731. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3732. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3733. {
  3734. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3735. result = FAIL;
  3736. goto end;
  3737. }
  3738. }// END FOR ELSE
  3739. }
  3740. } // END FOR GB_QUANTITY
  3741. }
  3742. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3743. {
  3744. tempIndex = connectorIdInt -1;
  3745. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3746. {
  3747. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3748. {
  3749. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3750. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3751. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3752. {
  3753. //Reserved
  3754. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3755. }
  3756. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3757. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3758. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3759. {
  3760. //Reserved
  3761. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3762. result = FAIL;
  3763. goto end;
  3764. }
  3765. else
  3766. {
  3767. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3768. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3769. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3770. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3771. {
  3772. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3773. result = FAIL;
  3774. goto end;
  3775. }
  3776. }// END FOR ELSE
  3777. }
  3778. } // END FOR GB_QUANTITY
  3779. }
  3780. else
  3781. {
  3782. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3783. {
  3784. tempIndex = 2;
  3785. }
  3786. else
  3787. {
  3788. tempIndex = connectorIdInt -1;
  3789. }
  3790. for (int index = 0; index < AC_QUANTITY; index++)
  3791. {
  3792. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3793. {
  3794. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3795. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3796. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3797. {
  3798. //Reserved
  3799. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3800. }
  3801. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3802. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3803. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3804. {
  3805. //Reserved
  3806. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3807. result = FAIL;
  3808. goto end;
  3809. }
  3810. else
  3811. {
  3812. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3813. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3814. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3815. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3816. {
  3817. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3818. result = FAIL;
  3819. goto end;
  3820. }
  3821. }//END FOR ELSE
  3822. }
  3823. }// END FOR AC_QUANTITY
  3824. }
  3825. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3826. {
  3827. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3828. {
  3829. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3830. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3831. {
  3832. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3833. system(cmdBuf);
  3834. }
  3835. }
  3836. else
  3837. {
  3838. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3839. result = FAIL;
  3840. }
  3841. }
  3842. end:
  3843. if(result == PASS)
  3844. {
  3845. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3846. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3847. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3848. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3849. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3850. }
  3851. }
  3852. void CheckSystemValue(void)
  3853. {
  3854. char filenmae[100]={0};
  3855. char str[100]={0};
  3856. int tempIndex = 0;
  3857. //===============================
  3858. // send Heartbeat
  3859. //===============================
  3860. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3861. {
  3862. //parameter for test
  3863. sendHeartbeatRequest(0);
  3864. //==============================================
  3865. // Reset Waiting Time
  3866. //==============================================
  3867. HeartBeatWithNOResponse += 2;
  3868. }
  3869. //===============================
  3870. // Credit deduct report
  3871. //===============================
  3872. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3873. {
  3874. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3875. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3876. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3877. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3878. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3879. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3880. }
  3881. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3882. {
  3883. OCPP_query_deduct_info();
  3884. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3885. }
  3886. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3887. {
  3888. // ClockAlign MeterValue
  3889. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3890. {
  3891. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3892. {
  3893. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3894. {
  3895. tempIndex = ((gun_index==2) ? 1: 0);
  3896. }
  3897. else
  3898. {
  3899. tempIndex = gun_index;
  3900. }
  3901. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3902. {
  3903. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3904. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3905. {
  3906. reqClockAlignMeter[gun_index] = 1;
  3907. }
  3908. }// End for CHAdeMO
  3909. }
  3910. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3911. {
  3912. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3913. {
  3914. tempIndex = ((gun_index==2) ? 1: 0);
  3915. }
  3916. else
  3917. {
  3918. tempIndex = gun_index;
  3919. }
  3920. for (int index = 0; index < CCS_QUANTITY; index++)
  3921. {
  3922. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3923. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3924. {
  3925. reqClockAlignMeter[gun_index] = 1;
  3926. }
  3927. } // End for CCS
  3928. }
  3929. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3930. {
  3931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3932. {
  3933. tempIndex = ((gun_index==2) ? 1: 0);
  3934. }
  3935. else
  3936. {
  3937. tempIndex = gun_index;
  3938. }
  3939. for (int index = 0; index < GB_QUANTITY; index++)
  3940. {
  3941. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3942. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3943. {
  3944. reqClockAlignMeter[gun_index] = 1;
  3945. }
  3946. }// End for GB
  3947. }
  3948. else if(gunType[gun_index] == GUN_TYPE_DO)
  3949. {
  3950. tempIndex = gun_index;
  3951. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3952. {
  3953. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3954. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3955. {
  3956. reqClockAlignMeter[gun_index] = 1;
  3957. }
  3958. }
  3959. }
  3960. else
  3961. {
  3962. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3963. {
  3964. tempIndex = 2;
  3965. }
  3966. else
  3967. {
  3968. tempIndex = gun_index;
  3969. }
  3970. for (int index = 0; index < AC_QUANTITY; index++)
  3971. {
  3972. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3973. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3974. {
  3975. reqClockAlignMeter[gun_index] = 1;
  3976. }
  3977. }//End for AC
  3978. }
  3979. }
  3980. }
  3981. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3982. {
  3983. //==========================================
  3984. // Check remote start without connector id
  3985. //==========================================
  3986. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3987. {
  3988. int connectorIdInt = -1;
  3989. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3990. {
  3991. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3992. {
  3993. connectorIdInt = (gun_index+1);
  3994. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3995. checkRemoteStart(connectorIdInt);
  3996. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3997. break;
  3998. }
  3999. }
  4000. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4001. {
  4002. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4003. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4004. }
  4005. }
  4006. //==========================================
  4007. // csu trigger DataTransferReq
  4008. //==========================================
  4009. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4010. {
  4011. sendDataTransferRequest(gun_index);
  4012. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4013. }
  4014. //===============================
  4015. // CSU Trigger Authorize Request
  4016. //===============================
  4017. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4018. {
  4019. sendAuthorizeRequest(0);
  4020. authorizeRetryTimes = authorizeRetryTimes + 1;
  4021. if(authorizeRetryTimes < 3)
  4022. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4023. }
  4024. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4025. {
  4026. authorizeRetryTimes = 0;
  4027. SetOcppConnStatus(FALSE);
  4028. server_sign = FALSE;
  4029. }
  4030. 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))
  4031. {
  4032. sendAuthorizeRequest(0);
  4033. }
  4034. //==============================================
  4035. // Charger start transaction
  4036. //==============================================
  4037. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4038. {
  4039. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4040. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4041. sendStartTransactionRequest(gun_index);
  4042. refreshStartTimer(&clientTime.StartTransaction);
  4043. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4044. //storeTempStopTransaction(gun_index);
  4045. }
  4046. //==============================================
  4047. // Charger stop transaction
  4048. //==============================================
  4049. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4050. {
  4051. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4052. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4053. sendStopTransactionRequest(gun_index);
  4054. refreshStartTimer(&clientTime.StopTransaction);
  4055. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4056. }
  4057. //==============================================
  4058. // Charger status report
  4059. //==============================================
  4060. //--- Check Mode Change ---//
  4061. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4062. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4063. {
  4064. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4065. {
  4066. tempIndex = ((gun_index==2) ? 1: 0);
  4067. }
  4068. else
  4069. {
  4070. tempIndex = gun_index;
  4071. }
  4072. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4073. {
  4074. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4075. {
  4076. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4077. {
  4078. // Sent unplug message for California pricing logic
  4079. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4080. {
  4081. uint8_t ts[36];
  4082. getNowDatetime(ts);
  4083. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4084. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4085. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4086. sendUnplugByDataTransferRequest(gun_index);
  4087. interLock.isSentUnplug[gun_index] = 1;
  4088. }
  4089. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4090. {
  4091. interLock.isSentUnplug[gun_index] = 0;
  4092. }
  4093. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4094. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4095. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4096. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4097. {
  4098. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4099. if((access(filenmae,F_OK))!=-1)
  4100. {
  4101. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4102. sprintf(str,"rm -f %s",filenmae);
  4103. system(str);
  4104. }
  4105. }
  4106. }
  4107. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4108. #if 1 // for TempStopTransaction
  4109. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4110. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4111. {
  4112. checkTempStopTransaction(gun_index);
  4113. }
  4114. #endif
  4115. }
  4116. }
  4117. }
  4118. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4119. {
  4120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4121. {
  4122. tempIndex = ((gun_index==2) ? 1: 0);
  4123. }
  4124. else
  4125. {
  4126. tempIndex = gun_index;
  4127. }
  4128. for (int index = 0; index < CCS_QUANTITY; index++)
  4129. {
  4130. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4131. {
  4132. 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]*/ )
  4133. {
  4134. // Sent unplug message for California pricing logic
  4135. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4136. {
  4137. uint8_t ts[36];
  4138. getNowDatetime(ts);
  4139. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4140. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4141. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4142. sendUnplugByDataTransferRequest(gun_index);
  4143. interLock.isSentUnplug[gun_index] = 1;
  4144. }
  4145. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4146. {
  4147. interLock.isSentUnplug[gun_index] = 0;
  4148. }
  4149. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4150. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4151. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4152. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4153. {
  4154. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4155. if((access(filenmae,F_OK))!=-1)
  4156. {
  4157. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4158. sprintf(str,"rm -f %s",filenmae);
  4159. system(str);
  4160. }
  4161. }
  4162. }
  4163. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4164. #if 1 // for TempStopTransaction
  4165. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4166. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4167. {
  4168. checkTempStopTransaction(gun_index);
  4169. }
  4170. #endif
  4171. }
  4172. }
  4173. }
  4174. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4175. {
  4176. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4177. {
  4178. tempIndex = ((gun_index==2) ? 1: 0);
  4179. }
  4180. else
  4181. {
  4182. tempIndex = gun_index;
  4183. }
  4184. for (int index = 0; index < GB_QUANTITY; index++)
  4185. {
  4186. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4187. {
  4188. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4189. {
  4190. // Sent unplug message for California pricing logic
  4191. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4192. {
  4193. uint8_t ts[36];
  4194. getNowDatetime(ts);
  4195. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4196. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4197. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4198. sendUnplugByDataTransferRequest(gun_index);
  4199. interLock.isSentUnplug[gun_index] = 1;
  4200. }
  4201. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4202. {
  4203. interLock.isSentUnplug[gun_index] = 0;
  4204. }
  4205. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4206. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4207. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4208. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4209. {
  4210. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4211. if((access(filenmae,F_OK))!=-1)
  4212. {
  4213. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4214. sprintf(str,"rm -f %s",filenmae);
  4215. system(str);
  4216. }
  4217. }
  4218. }
  4219. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4220. #if 1 // for TempStopTransaction
  4221. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4222. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4223. {
  4224. checkTempStopTransaction(gun_index);
  4225. }
  4226. #endif
  4227. }
  4228. }
  4229. }
  4230. else if(gunType[gun_index] == GUN_TYPE_DO)
  4231. {
  4232. tempIndex = gun_index;
  4233. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4234. {
  4235. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4236. {
  4237. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4238. {
  4239. // Sent unplug message for California pricing logic
  4240. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4241. {
  4242. uint8_t ts[36];
  4243. getNowDatetime(ts);
  4244. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4245. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4246. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4247. sendUnplugByDataTransferRequest(gun_index);
  4248. interLock.isSentUnplug[gun_index] = 1;
  4249. }
  4250. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4251. {
  4252. interLock.isSentUnplug[gun_index] = 0;
  4253. }
  4254. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4255. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4256. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4257. 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
  4258. {
  4259. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4260. if((access(filenmae,F_OK))!=-1)
  4261. {
  4262. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4263. sprintf(str,"rm -f %s",filenmae);
  4264. system(str);
  4265. }
  4266. }
  4267. }
  4268. 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);
  4269. #if 1 // for TempStopTransaction
  4270. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4271. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4272. {
  4273. checkTempStopTransaction(gun_index);
  4274. }
  4275. #endif
  4276. }
  4277. }
  4278. }
  4279. else
  4280. {
  4281. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4282. {
  4283. tempIndex = 2;
  4284. }
  4285. else
  4286. {
  4287. tempIndex = gun_index;
  4288. }
  4289. for (int index = 0; index < AC_QUANTITY; index++)
  4290. {
  4291. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4292. {
  4293. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4294. {
  4295. // Sent unplug message for California pricing logic
  4296. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4297. {
  4298. uint8_t ts[36];
  4299. getNowDatetime(ts);
  4300. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4301. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4302. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4303. sendUnplugByDataTransferRequest(gun_index);
  4304. interLock.isSentUnplug[gun_index] = 1;
  4305. }
  4306. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4307. {
  4308. interLock.isSentUnplug[gun_index] = 0;
  4309. }
  4310. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4311. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4312. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4313. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4314. {
  4315. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4316. if((access(filenmae,F_OK))!=-1)
  4317. {
  4318. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4319. sprintf(str,"rm -f %s",filenmae);
  4320. system(str);
  4321. }
  4322. }
  4323. }
  4324. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4325. #if 1 // for TempStopTransaction
  4326. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4327. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4328. {
  4329. checkTempStopTransaction(gun_index);
  4330. }
  4331. #endif
  4332. }
  4333. }// END
  4334. }
  4335. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4336. (
  4337. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4338. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4339. )
  4340. )
  4341. {
  4342. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4343. sendStatusNotificationRequest(gun_index);
  4344. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4345. }
  4346. //==============================================
  4347. // TCCI reader status report
  4348. //==============================================
  4349. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4350. {
  4351. reportReaderStatus(gun_index);
  4352. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4353. }
  4354. //==============================================
  4355. // CSU Trigger Smart Charging Profile
  4356. //==============================================
  4357. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4358. {
  4359. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4360. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4361. }
  4362. //==============================================
  4363. // Meter report
  4364. //==============================================
  4365. // Trigger MeterValue
  4366. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4367. {
  4368. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4369. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4370. }
  4371. // Clock-aligned Meter value
  4372. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4373. {
  4374. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4375. reqClockAlignMeter[gun_index] = 0;
  4376. }
  4377. // Sample period MeterValue
  4378. 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))))
  4379. {
  4380. //check Transaction active
  4381. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4382. {
  4383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4384. {
  4385. tempIndex = ((gun_index==2) ? 1: 0);
  4386. }
  4387. else
  4388. {
  4389. tempIndex = gun_index;
  4390. }
  4391. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4392. {
  4393. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4394. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4395. {
  4396. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4397. {
  4398. reqSampleMeter[gun_index] = 1;
  4399. }
  4400. }
  4401. }// End for CHAdeMO
  4402. }
  4403. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4404. {
  4405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4406. {
  4407. tempIndex = ((gun_index==2) ? 1: 0);
  4408. }
  4409. else
  4410. {
  4411. tempIndex = gun_index;
  4412. }
  4413. for (int index = 0; index < CCS_QUANTITY; index++)
  4414. {
  4415. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4416. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4417. {
  4418. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4419. {
  4420. reqSampleMeter[gun_index] = 1;
  4421. }
  4422. }
  4423. } // End for CCS
  4424. }
  4425. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4426. {
  4427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4428. {
  4429. tempIndex = ((gun_index==2) ? 1: 0);
  4430. }
  4431. else
  4432. {
  4433. tempIndex = gun_index;
  4434. }
  4435. for (int index = 0; index < GB_QUANTITY; index++)
  4436. {
  4437. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4438. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4439. {
  4440. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4441. {
  4442. reqSampleMeter[gun_index] = 1;
  4443. }
  4444. }
  4445. }// End for GB
  4446. }
  4447. else if(gunType[gun_index] == GUN_TYPE_DO)
  4448. {
  4449. tempIndex = gun_index;
  4450. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4451. {
  4452. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4453. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4454. {
  4455. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4456. {
  4457. reqSampleMeter[gun_index] = 1;
  4458. }
  4459. }
  4460. }
  4461. }
  4462. else
  4463. {
  4464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4465. {
  4466. tempIndex = 2;
  4467. }
  4468. else
  4469. {
  4470. tempIndex = gun_index;
  4471. }
  4472. for (int index = 0; index < AC_QUANTITY; index++)
  4473. {
  4474. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4475. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4476. {
  4477. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4478. {
  4479. reqSampleMeter[gun_index] = 1;
  4480. }
  4481. }
  4482. }//End for AC
  4483. }
  4484. if(reqSampleMeter[gun_index] == 1)
  4485. {
  4486. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4487. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4488. //storeTempStopTransaction(gun_index);
  4489. reqSampleMeter[gun_index] = 0;
  4490. }
  4491. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4492. }
  4493. //==============================================
  4494. // Check Connector reserved
  4495. //==============================================
  4496. //===============================
  4497. // Check if Reserve is expired
  4498. //===============================
  4499. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4500. {
  4501. double diff_t;
  4502. struct tm tp;
  4503. // current time
  4504. time_t t = time(NULL);
  4505. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4506. tp.tm_isdst = -1;
  4507. time_t utc = mktime(&tp);
  4508. diff_t = difftime(utc, t);
  4509. if(diff_t <= 0)
  4510. {
  4511. DEBUG_INFO("reserve expired.\n");
  4512. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4513. }
  4514. }//END OF Check if Reserve is expired
  4515. //==========================================
  4516. // csu trigger FirmwareStatusNotificationReq
  4517. //==========================================
  4518. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4519. {
  4520. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4521. }
  4522. //==========================================
  4523. // csu trigger DiagnosticsStatusNotificationReq
  4524. //==========================================
  4525. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4526. {
  4527. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4528. }
  4529. //==========================================
  4530. // csu trigger CancelReservationConf
  4531. //==========================================
  4532. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4533. {
  4534. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4535. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4536. }
  4537. //==========================================
  4538. // csu trigger ChangeAvailabilityConf
  4539. //==========================================
  4540. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4541. {
  4542. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4543. }
  4544. //==========================================
  4545. // csu trigger UnlockConnectorConf
  4546. //==========================================
  4547. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4548. {
  4549. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4550. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4551. }
  4552. //==========================================
  4553. // csu trigger ReserveNowConf
  4554. //==========================================
  4555. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4556. {
  4557. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4558. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4559. }
  4560. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4561. {
  4562. sendSignCertificateRequest();
  4563. }
  4564. }
  4565. }
  4566. //==========================================
  4567. // send request routine
  4568. //==========================================
  4569. int sendAuthorizeRequest(int gun_index)
  4570. {
  4571. mtrace();
  4572. int result = FAIL;
  4573. char message[100]={0};
  4574. char guid[37];
  4575. char tempdata[65]={0};
  4576. DEBUG_INFO("sendAuthorizeRequest...\n");
  4577. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4578. //Local Authorize
  4579. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4580. {
  4581. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4582. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4583. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4584. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4585. result = PASS;
  4586. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4587. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4588. authorizeRetryTimes = 0;
  4589. return result;
  4590. }
  4591. 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))||
  4592. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4593. {
  4594. // Query from cache
  4595. DEBUG_INFO("Authorize from cache.\n");
  4596. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4597. // Query from list
  4598. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4599. {
  4600. DEBUG_INFO("Authorize from list.\n");
  4601. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4602. }
  4603. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4604. {
  4605. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4606. {
  4607. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4608. }
  4609. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4610. {
  4611. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4612. }
  4613. if(!GetOcppConnStatus())
  4614. {
  4615. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4616. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4617. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4618. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4619. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4620. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4621. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4622. authorizeRetryTimes = 0;
  4623. return result;
  4624. }
  4625. }
  4626. else
  4627. {
  4628. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4629. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4630. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4631. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4632. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4633. else
  4634. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4635. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4636. result = PASS;
  4637. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4638. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4639. authorizeRetryTimes = 0;
  4640. return result;
  4641. }
  4642. }
  4643. //initialize struct Authorize
  4644. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4645. //get data from shared memory
  4646. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4647. random_uuid(guid);
  4648. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4649. LWS_Send(message);
  4650. sprintf(tempdata, "Authorize,%d", gun_index);
  4651. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4652. {
  4653. result = PASS;
  4654. DEBUG_INFO("Authorize mapItem pass\n");
  4655. }
  4656. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4657. return result;
  4658. }
  4659. int sendBootNotificationRequest(void)
  4660. {
  4661. mtrace();
  4662. int result = FAIL;
  4663. char message[500]={0}, payload[700]={0};
  4664. char guid[37]={0};
  4665. char tempdata[65]={0};
  4666. // Fill BootNotification fields
  4667. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4668. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4669. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4670. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4671. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4672. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4673. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4674. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4675. ShmOCPP16DataPH->ChargeBoxId
  4676. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4677. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4678. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4679. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4680. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4681. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4682. random_uuid(guid);
  4683. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4684. LWS_Send(message);
  4685. sprintf(tempdata, "BootNotification,0");
  4686. 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*/)
  4687. {
  4688. result = PASS;
  4689. }
  4690. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4691. strcpy(queuedata,message);
  4692. return result;
  4693. }
  4694. int sendDataTransferRequest(int gun_index)
  4695. {
  4696. mtrace();
  4697. char message[1000]={0};
  4698. char guid[37]={0};
  4699. char tempdata[65]={0};
  4700. int result = FAIL;
  4701. random_uuid(guid);
  4702. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4703. MESSAGE_TYPE_CALL,
  4704. guid,
  4705. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4706. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4707. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4708. LWS_Send(message);
  4709. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4710. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4711. {
  4712. result = PASS;
  4713. DEBUG_INFO("DataTransfer mapItem pass\n");
  4714. }
  4715. return result;
  4716. }
  4717. int sendUnplugByDataTransferRequest(int gun_index)
  4718. {
  4719. mtrace();
  4720. char message[1000]={0};
  4721. char guid[37]={0};
  4722. char tempdata[65]={0};
  4723. int result = FAIL;
  4724. random_uuid(guid);
  4725. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4726. (gun_index+1),
  4727. MESSAGE_TYPE_CALL,
  4728. guid,
  4729. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4730. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4731. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4732. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4733. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4734. {
  4735. result = PASS;
  4736. DEBUG_INFO("DataTransfer mapItem pass\n");
  4737. }
  4738. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  4739. return result;
  4740. }
  4741. int sendDiagnosticsStatusNotificationRequest(char *status)
  4742. {
  4743. mtrace();
  4744. int result = FAIL;
  4745. char message[110]={0};
  4746. char guid[37]={0};
  4747. char tempdata[65]={0};
  4748. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4749. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4750. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4751. random_uuid(guid);
  4752. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4753. LWS_SendNow(message);
  4754. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4755. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4756. {
  4757. result = PASS;
  4758. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4759. }
  4760. //#ifdef SystemLogMessage
  4761. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4762. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4763. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4764. //#endif
  4765. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4766. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4767. //record status
  4768. if(strcmp(status,"Idle")==0)
  4769. {
  4770. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4771. }
  4772. else if(strcmp(status,"Uploaded")==0)
  4773. {
  4774. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4775. }
  4776. else if(strcmp(status,"UploadFailed")==0)
  4777. {
  4778. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4779. }
  4780. else if(strcmp(status,"Uploading")==0)
  4781. {
  4782. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4783. }
  4784. return result;
  4785. }
  4786. int sendFirmwareStatusNotificationRequest(char *status)
  4787. {
  4788. mtrace();
  4789. int result = FAIL;
  4790. char message[110]={0};
  4791. char guid[37]={0};
  4792. char tempdata[65]={0};
  4793. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4794. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4795. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4796. random_uuid(guid);
  4797. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4798. LWS_SendNow(message);
  4799. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4800. 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*/)
  4801. {
  4802. result = PASS;
  4803. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4804. }
  4805. //#ifdef SystemLogMessage
  4806. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4807. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4808. //#endif
  4809. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4810. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4811. //record status
  4812. if(strcmp(status,"Downloaded")==0)
  4813. {
  4814. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4815. }
  4816. else if(strcmp(status,"DownloadFailed")==0)
  4817. {
  4818. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4819. }
  4820. else if(strcmp(status,"Downloading")==0)
  4821. {
  4822. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4823. }
  4824. else if(strcmp(status,"Idle")==0)
  4825. {
  4826. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4827. }
  4828. else if(strcmp(status,"InstallationFailed")==0)
  4829. {
  4830. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4831. }
  4832. else if(strcmp(status,"Installing")==0)
  4833. {
  4834. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4835. }
  4836. else if(strcmp(status,"Installed")==0)
  4837. {
  4838. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4839. }
  4840. return result;
  4841. }
  4842. int sendHeartbeatRequest(int gun_index)
  4843. {
  4844. mtrace();
  4845. int result = FAIL;
  4846. char message[80]={0};
  4847. char guid[37]={0};
  4848. char tempdata[65]={0};
  4849. random_uuid(guid);
  4850. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4851. , MESSAGE_TYPE_CALL
  4852. , guid );
  4853. LWS_Send(message);
  4854. sprintf(tempdata, "Heartbeat,%d", 0);
  4855. 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*/)
  4856. {
  4857. result = PASS;
  4858. }
  4859. return result;
  4860. }
  4861. int sendStartTransactionRequest(int gun_index)
  4862. {
  4863. mtrace();
  4864. int result = FAIL;
  4865. char message[250]={0};
  4866. char guid[37]={0};
  4867. struct timeval tmnow;
  4868. struct tm *tm;
  4869. char buf[28];//, usec_buf[6];
  4870. char tempdata[65]={0};
  4871. int tempIndex = 0;
  4872. DEBUG_INFO("sendStartTransactionRequest...\n");
  4873. gettimeofday(&tmnow, NULL);
  4874. time_t t;
  4875. t = time(NULL);
  4876. /*UTC time and date*/
  4877. tm = gmtime(&t);
  4878. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4879. #if 0 // remove temporally
  4880. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4881. strcat(buf,".");
  4882. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4883. strcat(buf,usec_buf);
  4884. #endif
  4885. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4886. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4887. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4888. // clear StartTransaction Response
  4889. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4890. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4891. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4892. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4893. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4894. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4895. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4896. {
  4897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4898. {
  4899. tempIndex = ((gun_index==2) ? 1: 0);
  4900. }
  4901. else
  4902. {
  4903. tempIndex = gun_index;
  4904. }
  4905. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4906. {
  4907. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4908. {
  4909. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4910. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4911. }
  4912. }
  4913. }
  4914. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4915. {
  4916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4917. {
  4918. tempIndex = ((gun_index==2) ? 1: 0);
  4919. }
  4920. else
  4921. {
  4922. tempIndex = gun_index;
  4923. }
  4924. for (int index = 0; index < CCS_QUANTITY; index++)
  4925. {
  4926. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4927. {
  4928. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4929. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4930. }
  4931. }
  4932. }
  4933. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4934. {
  4935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4936. {
  4937. tempIndex = ((gun_index==2) ? 1: 0);
  4938. }
  4939. else
  4940. {
  4941. tempIndex = gun_index;
  4942. }
  4943. for (int index = 0; index < GB_QUANTITY; index++)
  4944. {
  4945. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4946. {
  4947. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4948. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4949. }
  4950. }
  4951. }
  4952. else if(gunType[gun_index] == GUN_TYPE_DO)
  4953. {
  4954. tempIndex = gun_index;
  4955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4956. {
  4957. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4958. {
  4959. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4960. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4961. }
  4962. }
  4963. }
  4964. else
  4965. {
  4966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4967. {
  4968. tempIndex = 2;
  4969. }
  4970. else
  4971. {
  4972. tempIndex = gun_index;
  4973. }
  4974. for (int index = 0; index < AC_QUANTITY; index++)
  4975. {
  4976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4977. {
  4978. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4979. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4980. }
  4981. }
  4982. }
  4983. random_uuid(guid);
  4984. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4985. {
  4986. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4987. , gun_index +1
  4988. , MESSAGE_TYPE_CALL
  4989. , guid
  4990. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4991. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4992. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4993. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4994. }
  4995. else
  4996. {
  4997. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4998. , gun_index +1
  4999. , MESSAGE_TYPE_CALL
  5000. , guid
  5001. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5002. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5003. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5004. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  5005. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5006. }
  5007. #if 1
  5008. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5009. 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*/)
  5010. {
  5011. result = PASS;
  5012. }
  5013. #endif
  5014. strcpy(queuedata, message);
  5015. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5016. OCPP_insert_transaction_msg(YES, queuedata);
  5017. return result;
  5018. }
  5019. int sendStatusNotificationRequest(int gun_index)
  5020. {
  5021. mtrace();
  5022. int result = FAIL;
  5023. char message[600]={0};
  5024. char guid[37];
  5025. int currentStatus = 0;
  5026. struct timeval tmnow;
  5027. struct tm *tm;
  5028. char buf[28];//, usec_buf[6];
  5029. char tempdata[65]={0};
  5030. int tempIndex = 0;
  5031. uint8_t isStateChanged = TRUE;
  5032. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5033. gettimeofday(&tmnow, NULL);
  5034. time_t t;
  5035. t = time(NULL);
  5036. /*UTC time and date*/
  5037. tm = gmtime(&t);
  5038. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5039. #if 0 // remove temporally
  5040. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5041. strcat(buf,".");
  5042. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5043. strcat(buf,usec_buf);
  5044. #endif
  5045. //printf("%s",buf);
  5046. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5047. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5048. // it's option
  5049. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5050. /*
  5051. enum _SYSTEM_STATUS
  5052. {
  5053. S_BOOTING = 0,
  5054. S_IDLE, = 1
  5055. S_AUTHORIZING, =2
  5056. S_REASSIGN_CHECK, =3
  5057. S_REASSIGN, =4
  5058. S_PRECHARGE, =5
  5059. S_PREPARING_FOR_EV, =6
  5060. S_PREPARING_FOR_EVSE, =7
  5061. S_CHARGING, =8
  5062. S_TERMINATING, =9
  5063. S_COMPLETE, =10
  5064. S_ALARM, =11
  5065. S_FAULT =12
  5066. }
  5067. */
  5068. //check Transaction active
  5069. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5070. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5071. {
  5072. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5073. {
  5074. tempIndex = ((gun_index==2) ? 1: 0);
  5075. }
  5076. else
  5077. {
  5078. tempIndex = gun_index;
  5079. }
  5080. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5081. {
  5082. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5083. {
  5084. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5085. {
  5086. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5087. {
  5088. currentStatus = Preparing; //OCPP Status: Preparing
  5089. }
  5090. else
  5091. {
  5092. currentStatus = Available; //OCPP Status: Available
  5093. }
  5094. }
  5095. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5096. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5097. ) //S_PRECHARGE
  5098. {
  5099. currentStatus = Preparing; //OCPP Status: Preparing
  5100. }
  5101. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5102. {
  5103. currentStatus = Charging; //OCPP Status: Charging
  5104. }
  5105. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5106. {
  5107. currentStatus = Finishing; //OCPP Status: Finishing
  5108. }
  5109. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5110. {
  5111. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5112. }
  5113. 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
  5114. {
  5115. currentStatus = Unavailable; //OCPP Status: Unavailable
  5116. }
  5117. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5118. {
  5119. currentStatus = Faulted; //OCPP Status: Faulted
  5120. }
  5121. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5122. {
  5123. currentStatus = Reserved; //OCPP Status: Reserved
  5124. }
  5125. } //end of the same index
  5126. }//end of for CHAdeMO_QUANTITY
  5127. }
  5128. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5129. {
  5130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5131. {
  5132. tempIndex = ((gun_index==2) ? 1: 0);
  5133. }
  5134. else
  5135. {
  5136. tempIndex = gun_index;
  5137. }
  5138. for (int index = 0; index < CCS_QUANTITY; index++)
  5139. {
  5140. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5141. {
  5142. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5143. {
  5144. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5145. {
  5146. currentStatus = Preparing; //OCPP Status: Preparing
  5147. }
  5148. else
  5149. {
  5150. currentStatus = Available; //OCPP Status: Available
  5151. }
  5152. }
  5153. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5154. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5155. ) //S_PRECHARGE
  5156. {
  5157. currentStatus = Preparing; //OCPP Status: Preparing
  5158. }
  5159. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5160. {
  5161. currentStatus = Charging; //OCPP Status: Charging
  5162. }
  5163. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5164. {
  5165. currentStatus = Finishing; //OCPP Status: Finishing
  5166. }
  5167. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5168. {
  5169. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5170. }
  5171. 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
  5172. {
  5173. currentStatus = Unavailable; //OCPP Status : Unavailable
  5174. }
  5175. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5176. {
  5177. currentStatus = Faulted; //OCPP Status: Faulted
  5178. }
  5179. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5180. {
  5181. currentStatus = Reserved; //OCPP Status: Reserved
  5182. }
  5183. } //end of the same index
  5184. } // end of for CCS_QUANTITY
  5185. }
  5186. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5187. {
  5188. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5189. {
  5190. tempIndex = ((gun_index==2) ? 1: 0);
  5191. }
  5192. else
  5193. {
  5194. tempIndex = gun_index;
  5195. }
  5196. for (int index = 0; index < GB_QUANTITY; index++)
  5197. {
  5198. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5199. {
  5200. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5201. {
  5202. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5203. {
  5204. currentStatus = Preparing; //OCPP Status: Preparing
  5205. }
  5206. else
  5207. {
  5208. currentStatus = Available; //OCPP Status: Available
  5209. }
  5210. }
  5211. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5212. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5213. ) //S_PRECHARGE
  5214. {
  5215. currentStatus = Preparing; //OCPP Status: Preparing
  5216. }
  5217. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5218. {
  5219. currentStatus = Charging; //OCPP Status: Charging
  5220. }
  5221. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5222. {
  5223. currentStatus = Finishing; //OCPP Status: Finishing
  5224. }
  5225. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5226. {
  5227. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5228. }
  5229. 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
  5230. {
  5231. currentStatus = Unavailable; //OCPP Status: Unavailable
  5232. }
  5233. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5234. {
  5235. currentStatus = Faulted; //OCPP Status: Faulted
  5236. }
  5237. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5238. {
  5239. currentStatus = Reserved; //OCPP Status: Reserved
  5240. }
  5241. } //end of the same index
  5242. } // end of for GB_QUANTITY
  5243. }
  5244. else if(gunType[gun_index] == GUN_TYPE_DO)
  5245. {
  5246. tempIndex = gun_index;
  5247. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5248. {
  5249. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5250. {
  5251. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5252. {
  5253. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5254. {
  5255. currentStatus = Preparing; //OCPP Status: Preparing
  5256. }
  5257. else
  5258. {
  5259. currentStatus = Available; //OCPP Status: Available
  5260. }
  5261. }
  5262. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5263. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5264. ) //S_PRECHARGE
  5265. {
  5266. currentStatus = Preparing; //OCPP Status: Preparing
  5267. }
  5268. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5269. {
  5270. currentStatus = Charging; //OCPP Status: Charging
  5271. }
  5272. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5273. {
  5274. currentStatus = Finishing; //OCPP Status: Finishing
  5275. }
  5276. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5277. {
  5278. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5279. }
  5280. 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
  5281. {
  5282. currentStatus = Unavailable; //OCPP Status: Unavailable
  5283. }
  5284. 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
  5285. {
  5286. currentStatus = Faulted; //OCPP Status: Faulted
  5287. }
  5288. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5289. {
  5290. currentStatus = Reserved; //OCPP Status: Reserved
  5291. }
  5292. } //end of the same index
  5293. }
  5294. }
  5295. else
  5296. {
  5297. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5298. {
  5299. tempIndex = 2;
  5300. }
  5301. else
  5302. {
  5303. tempIndex = gun_index;
  5304. }
  5305. for (int index = 0; index < AC_QUANTITY; index++)
  5306. {
  5307. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5308. {
  5309. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5310. {
  5311. 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))
  5312. {
  5313. currentStatus = Preparing; //OCPP Status: Preparing
  5314. }
  5315. else
  5316. {
  5317. currentStatus = Available; //OCPP Status: Available
  5318. }
  5319. }
  5320. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5321. {
  5322. currentStatus = Preparing; //OCPP Status: Preparing
  5323. }
  5324. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5325. {
  5326. currentStatus = Charging; //OCPP Status: Charging
  5327. }
  5328. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5329. {
  5330. currentStatus = Finishing; //OCPP Status: Finishing
  5331. }
  5332. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5333. {
  5334. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5335. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5336. else
  5337. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5338. }
  5339. 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
  5340. {
  5341. currentStatus = Unavailable; //OCPP Status: Unavailable
  5342. }
  5343. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5344. {
  5345. currentStatus = Faulted; //OCPP Status: Faulted
  5346. }
  5347. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5348. {
  5349. currentStatus = Reserved; //OCPP Status: Reserved
  5350. }
  5351. }//end of the same index
  5352. }//end of for AC_QUANTITY
  5353. }
  5354. //it's option
  5355. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5356. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5357. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5358. {
  5359. isStateChanged = FALSE;
  5360. }
  5361. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5362. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5363. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5364. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5365. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5366. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5367. random_uuid(guid);
  5368. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5369. , MESSAGE_TYPE_CALL
  5370. , guid
  5371. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5372. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5373. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5374. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5375. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5376. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5377. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5378. if((server_sign == TRUE) && isStateChanged)
  5379. {
  5380. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5381. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5382. LWS_Send(message);
  5383. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5384. 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*/)
  5385. {
  5386. //DEBUG_ERROR("statusNotification mapitem pass");
  5387. result = PASS;
  5388. }
  5389. }
  5390. else
  5391. {
  5392. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5393. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5394. result = PASS;
  5395. }
  5396. return result;
  5397. }
  5398. int sendStopTransactionRequest(int gun_index)
  5399. {
  5400. mtrace();
  5401. int result = FAIL;
  5402. //char message[1500]={0};
  5403. char guid[37]={0};
  5404. char tempdata[65]={0};
  5405. int tempIndex = 0;
  5406. char TempStopTransaction[256];
  5407. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5408. //int idx_sample=0;
  5409. DEBUG_INFO("sendStopTransactionRequest \n");
  5410. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5411. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5412. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5413. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5414. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5415. {
  5416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5417. {
  5418. tempIndex = ((gun_index==2) ? 1: 0);
  5419. }
  5420. else
  5421. {
  5422. tempIndex = gun_index;
  5423. }
  5424. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5425. {
  5426. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5427. {
  5428. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5429. }
  5430. }// END OF CHAdeMO_QUANTITY
  5431. }
  5432. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5433. {
  5434. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5435. {
  5436. tempIndex = ((gun_index==2) ? 1: 0);
  5437. }
  5438. else
  5439. {
  5440. tempIndex = gun_index;
  5441. }
  5442. for (int index = 0; index < CCS_QUANTITY; index++)
  5443. {
  5444. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5445. {
  5446. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5447. }
  5448. }// END OF CCS_QUANTITY
  5449. }
  5450. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5451. {
  5452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5453. {
  5454. tempIndex = ((gun_index==2) ? 1: 0);
  5455. }
  5456. else
  5457. {
  5458. tempIndex = gun_index;
  5459. }
  5460. for (int index = 0; index < GB_QUANTITY; index++)
  5461. {
  5462. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5463. {
  5464. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5465. }
  5466. }// END OF GB_QUANTITY
  5467. }
  5468. else if(gunType[gun_index] == GUN_TYPE_DO)
  5469. {
  5470. tempIndex = gun_index;
  5471. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5472. {
  5473. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5474. {
  5475. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5476. }
  5477. }// END OF GB_QUANTITY
  5478. }
  5479. else
  5480. {
  5481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5482. {
  5483. tempIndex = 2;
  5484. }
  5485. else
  5486. {
  5487. tempIndex = gun_index;
  5488. }
  5489. for (int index = 0; index < AC_QUANTITY; index++)
  5490. {
  5491. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5492. {
  5493. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5494. }
  5495. }// END OF AC_QUANTITY
  5496. }
  5497. //====================================== Stop Transaction Time =====================================================
  5498. struct timeval tmnow;
  5499. struct tm *tm;
  5500. char buf[28];//, usec_buf[6];
  5501. gettimeofday(&tmnow, NULL);
  5502. time_t t;
  5503. t = time(NULL);
  5504. /*UTC time and date*/
  5505. tm = gmtime(&t);
  5506. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5507. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5508. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5509. random_uuid(guid);
  5510. /***********************************transactionData******************************************************/
  5511. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5512. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5513. //=================================
  5514. // Transaction_Begin
  5515. //=================================
  5516. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5517. {
  5518. //============================================ Energy.Active.Import.Interval ================================
  5519. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5520. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5521. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5522. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  5523. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5524. 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))
  5525. {
  5526. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5527. }
  5528. else
  5529. {
  5530. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5531. }
  5532. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5533. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5534. }
  5535. //=================================
  5536. // Transaction_End
  5537. //=================================
  5538. // ================================= Current.Import L1 ===============================================
  5539. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5540. {
  5541. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5542. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5543. {
  5544. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5545. {
  5546. tempIndex = ((gun_index==2) ? 1: 0);
  5547. }
  5548. else
  5549. {
  5550. tempIndex = gun_index;
  5551. }
  5552. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5553. {
  5554. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5555. {
  5556. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5557. }
  5558. }// End of for CHAdeMO_QUANTITY
  5559. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5560. }
  5561. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5562. {
  5563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5564. {
  5565. tempIndex = ((gun_index==2) ? 1: 0);
  5566. }
  5567. else
  5568. {
  5569. tempIndex = gun_index;
  5570. }
  5571. for (int index = 0; index < CCS_QUANTITY; index++)
  5572. {
  5573. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5574. {
  5575. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5576. }
  5577. }// End of for CCS_QUANTITY
  5578. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5579. }
  5580. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5581. {
  5582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5583. {
  5584. tempIndex = ((gun_index==2) ? 1: 0);
  5585. }
  5586. else
  5587. {
  5588. tempIndex = gun_index;
  5589. }
  5590. for (int index = 0; index < GB_QUANTITY; index++)
  5591. {
  5592. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5593. {
  5594. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5595. }
  5596. }// End of for GB_QUANTITY
  5597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5598. }
  5599. else if(gunType[gun_index] == GUN_TYPE_DO)
  5600. {
  5601. tempIndex = gun_index;
  5602. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5603. {
  5604. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5605. {
  5606. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5607. }
  5608. }
  5609. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5610. }
  5611. else
  5612. {
  5613. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5614. {
  5615. tempIndex = 2;
  5616. }
  5617. else
  5618. {
  5619. tempIndex = gun_index;
  5620. }
  5621. for (int index = 0; index < AC_QUANTITY; index++)
  5622. {
  5623. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5624. {
  5625. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5626. }
  5627. }// End of for AC_QUANTITY
  5628. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5629. }
  5630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5631. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5632. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5633. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5634. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5635. }
  5636. // ================================= Energy.Active.Import.Interval ==============================================
  5637. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5638. {
  5639. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5640. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5641. {
  5642. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5643. {
  5644. tempIndex = ((gun_index==2) ? 1: 0);
  5645. }
  5646. else
  5647. {
  5648. tempIndex = gun_index;
  5649. }
  5650. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5651. {
  5652. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5653. {
  5654. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5655. }
  5656. }// END OF CHAdeMO_QUANTITY
  5657. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5658. }
  5659. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5660. {
  5661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5662. {
  5663. tempIndex = ((gun_index==2) ? 1: 0);
  5664. }
  5665. else
  5666. {
  5667. tempIndex = gun_index;
  5668. }
  5669. for (int index = 0; index < CCS_QUANTITY; index++)
  5670. {
  5671. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5672. {
  5673. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5674. }
  5675. }// END OF CCS_QUANTITY
  5676. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5677. }
  5678. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5679. {
  5680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5681. {
  5682. tempIndex = ((gun_index==2) ? 1: 0);
  5683. }
  5684. else
  5685. {
  5686. tempIndex = gun_index;
  5687. }
  5688. for (int index = 0; index < GB_QUANTITY; index++)
  5689. {
  5690. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5691. {
  5692. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5693. }
  5694. }// END OF GB_QUANTITY
  5695. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5696. }
  5697. else if(gunType[gun_index] == GUN_TYPE_DO)
  5698. {
  5699. tempIndex = gun_index;
  5700. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5701. {
  5702. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5703. {
  5704. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5705. }
  5706. }
  5707. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5708. }
  5709. else
  5710. {
  5711. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5712. {
  5713. tempIndex = 2;
  5714. }
  5715. else
  5716. {
  5717. tempIndex = gun_index;
  5718. }
  5719. for (int index = 0; index < AC_QUANTITY; index++)
  5720. {
  5721. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5722. {
  5723. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5724. }
  5725. }// END OF AC_QUANTITY
  5726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5727. }
  5728. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5730. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5731. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5732. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5733. }
  5734. //=================================== Power.Active.Import ==================================================
  5735. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5736. {
  5737. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5738. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5739. {
  5740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5741. {
  5742. tempIndex = ((gun_index==2) ? 1: 0);
  5743. }
  5744. else
  5745. {
  5746. tempIndex = gun_index;
  5747. }
  5748. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5749. {
  5750. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5751. {
  5752. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5753. }
  5754. } // End for CHAdeMO_QUANTITY
  5755. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5756. }
  5757. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5758. {
  5759. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5760. {
  5761. tempIndex = ((gun_index==2) ? 1: 0);
  5762. }
  5763. else
  5764. {
  5765. tempIndex = gun_index;
  5766. }
  5767. for (int index = 0; index < CCS_QUANTITY; index++)
  5768. {
  5769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5770. {
  5771. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5772. }
  5773. } // END for CCS_QUANTITY
  5774. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5775. }
  5776. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5777. {
  5778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5779. {
  5780. tempIndex = ((gun_index==2) ? 1: 0);
  5781. }
  5782. else
  5783. {
  5784. tempIndex = gun_index;
  5785. }
  5786. for (int index = 0; index < GB_QUANTITY; index++)
  5787. {
  5788. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5789. {
  5790. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5791. }
  5792. }// END for GB_QUANTITY
  5793. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5794. }
  5795. else if(gunType[gun_index] == GUN_TYPE_DO)
  5796. {
  5797. tempIndex = gun_index;
  5798. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5799. {
  5800. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5801. {
  5802. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5803. }
  5804. }
  5805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5806. }
  5807. else
  5808. {
  5809. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5810. {
  5811. tempIndex = 2;
  5812. }
  5813. else
  5814. {
  5815. tempIndex = gun_index;
  5816. }
  5817. for (int index = 0; index < AC_QUANTITY; index++)
  5818. {
  5819. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5820. {
  5821. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5822. }
  5823. } // END for AC_QUANTITY
  5824. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5825. }
  5826. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5828. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5829. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5830. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5831. }
  5832. //============================ Voltage L1 ====================================
  5833. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5834. {
  5835. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5836. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5837. {
  5838. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5839. {
  5840. tempIndex = ((gun_index==2) ? 1: 0);
  5841. }
  5842. else
  5843. {
  5844. tempIndex = gun_index;
  5845. }
  5846. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5847. {
  5848. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5849. {
  5850. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5851. }
  5852. } // END OF FOR CHAdeMO_QUANTITY
  5853. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5854. }
  5855. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5856. {
  5857. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5858. {
  5859. tempIndex = ((gun_index==2) ? 1: 0);
  5860. }
  5861. else
  5862. {
  5863. tempIndex = gun_index;
  5864. }
  5865. for (int index = 0; index < CCS_QUANTITY; index++)
  5866. {
  5867. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5868. {
  5869. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5870. }
  5871. } // END OF FOR CCS_QUANTITY
  5872. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5873. }
  5874. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5875. {
  5876. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5877. {
  5878. tempIndex = ((gun_index==2) ? 1: 0);
  5879. }
  5880. else
  5881. {
  5882. tempIndex = gun_index;
  5883. }
  5884. for (int index = 0; index < GB_QUANTITY; index++)
  5885. {
  5886. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5887. {
  5888. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5889. }
  5890. } // END OF FOR GB_QUANTITY
  5891. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5892. }
  5893. else if(gunType[gun_index] == GUN_TYPE_DO)
  5894. {
  5895. tempIndex = gun_index;
  5896. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5897. {
  5898. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5899. {
  5900. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5901. }
  5902. }
  5903. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5904. }
  5905. else
  5906. {
  5907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5908. {
  5909. tempIndex = 2;
  5910. }
  5911. else
  5912. {
  5913. tempIndex = gun_index;
  5914. }
  5915. for (int index = 0; index < AC_QUANTITY; index++)
  5916. {
  5917. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5918. {
  5919. 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
  5920. }
  5921. } // END OF FOR AC_QUANTITY
  5922. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5923. }
  5924. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5925. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5926. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5927. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5928. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5929. }
  5930. //====================== End SoC ================================
  5931. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5932. {
  5933. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5934. 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))
  5935. {
  5936. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5937. {
  5938. tempIndex = ((gun_index==2) ? 1: 0);
  5939. }
  5940. else
  5941. {
  5942. tempIndex = gun_index;
  5943. }
  5944. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5945. {
  5946. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5947. {
  5948. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5949. {
  5950. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5951. }
  5952. }
  5953. }
  5954. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5955. {
  5956. for (int index = 0; index < CCS_QUANTITY; index++)
  5957. {
  5958. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5959. {
  5960. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5961. }
  5962. }
  5963. }
  5964. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5965. {
  5966. for (int index = 0; index < GB_QUANTITY; index++)
  5967. {
  5968. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5969. {
  5970. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5971. }
  5972. }
  5973. }
  5974. else if(gunType[gun_index] == GUN_TYPE_DO)
  5975. {
  5976. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5977. {
  5978. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5979. {
  5980. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5981. }
  5982. }
  5983. }
  5984. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5985. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5986. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5987. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5988. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5989. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5990. } // END FOR DC CASE
  5991. }
  5992. // ================================= Current.Import L2 ===============================================
  5993. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5994. {
  5995. // AC 3 phse L2 current
  5996. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5997. {
  5998. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5999. {
  6000. tempIndex = 2;
  6001. }
  6002. else
  6003. {
  6004. tempIndex = gun_index;
  6005. }
  6006. for (int index = 0; index < AC_QUANTITY; index++)
  6007. {
  6008. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6009. {
  6010. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6011. }
  6012. }// End of for AC_QUANTITY
  6013. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6014. }
  6015. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6016. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6017. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6018. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6019. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6020. }
  6021. // ================================= Current.Import L3 ===============================================
  6022. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6023. {
  6024. // AC 3 phse L3 current
  6025. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6026. {
  6027. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6028. {
  6029. tempIndex = 2;
  6030. }
  6031. else
  6032. {
  6033. tempIndex = gun_index;
  6034. }
  6035. for (int index = 0; index < AC_QUANTITY; index++)
  6036. {
  6037. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6038. {
  6039. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6040. }
  6041. }// End of for AC_QUANTITY
  6042. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6043. }
  6044. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6045. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6046. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6047. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6048. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6049. }
  6050. //============================ Voltage L2 ====================================
  6051. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6052. {
  6053. // AC 3 phse L2 voltage
  6054. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6055. {
  6056. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6057. {
  6058. tempIndex = 2;
  6059. }
  6060. else
  6061. {
  6062. tempIndex = gun_index;
  6063. }
  6064. for (int index = 0; index < AC_QUANTITY; index++)
  6065. {
  6066. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6067. {
  6068. 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
  6069. }
  6070. } // END OF FOR AC_QUANTITY
  6071. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6072. }
  6073. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6074. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6075. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6076. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6077. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6078. }
  6079. //============================ Voltage L3 ====================================
  6080. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6081. {
  6082. // AC 3 phse L3 voltage
  6083. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6084. {
  6085. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6086. {
  6087. tempIndex = 2;
  6088. }
  6089. else
  6090. {
  6091. tempIndex = gun_index;
  6092. }
  6093. for (int index = 0; index < AC_QUANTITY; index++)
  6094. {
  6095. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6096. {
  6097. 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
  6098. }
  6099. } // END OF FOR AC_QUANTITY
  6100. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6101. }
  6102. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6103. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6104. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6105. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6106. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6107. }
  6108. //====================== Start SoC ================================
  6109. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6110. {
  6111. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6112. 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))
  6113. {
  6114. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6115. {
  6116. tempIndex = ((gun_index==2) ? 1: 0);
  6117. }
  6118. else
  6119. {
  6120. tempIndex = gun_index;
  6121. }
  6122. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6123. {
  6124. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6125. {
  6126. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6127. {
  6128. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6129. }
  6130. }
  6131. }
  6132. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6133. {
  6134. for (int index = 0; index < CCS_QUANTITY; index++)
  6135. {
  6136. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6137. {
  6138. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6139. }
  6140. }
  6141. }
  6142. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6143. {
  6144. for (int index = 0; index < GB_QUANTITY; index++)
  6145. {
  6146. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6147. {
  6148. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6149. }
  6150. }
  6151. }
  6152. else if(gunType[gun_index] == GUN_TYPE_DO)
  6153. {
  6154. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6155. {
  6156. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6157. {
  6158. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6159. }
  6160. }
  6161. }
  6162. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6163. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6164. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6165. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6166. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6167. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6168. } // END FOR DC CASE
  6169. }
  6170. //================================================ Message create ====================================================
  6171. json_object *StopTransaction = json_object_new_object();
  6172. json_object *transactionDatas = json_object_new_array();
  6173. json_object *sampledValues = json_object_new_array();
  6174. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6175. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6176. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6177. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6178. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6179. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6180. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6181. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6182. {
  6183. json_object *transactionData = json_object_new_object();
  6184. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6185. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6186. {
  6187. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6188. {
  6189. json_object *sampledValue = json_object_new_object();
  6190. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6191. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6192. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6193. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6194. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6195. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6196. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6197. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6198. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6199. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6200. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6201. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6202. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6203. json_object_array_add(sampledValues, sampledValue);
  6204. }
  6205. }
  6206. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6207. json_object_array_add(transactionDatas, transactionData);
  6208. }
  6209. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6210. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6211. ,MESSAGE_TYPE_CALL
  6212. ,guid
  6213. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6214. json_object_put(StopTransaction);
  6215. #if 1 // for TempStopTransaction
  6216. //Delete TempStopTransaction
  6217. if((access(TempStopTransaction,F_OK))!=-1)
  6218. {
  6219. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6220. }
  6221. #endif
  6222. #if 1
  6223. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6224. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6225. {
  6226. result = PASS;
  6227. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6228. }
  6229. #endif
  6230. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6231. OCPP_insert_transaction_msg(NO, queuedata);
  6232. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6233. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6234. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6235. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6236. {
  6237. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6238. }
  6239. //for test
  6240. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6241. return result;
  6242. }
  6243. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6244. {
  6245. mtrace();
  6246. int result = FAIL;
  6247. char guid[37]={0};
  6248. char tempdata[65]={0};
  6249. int tempIndex = 0;
  6250. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6251. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6252. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6253. //set value
  6254. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6255. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6256. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6257. -1);
  6258. random_uuid(guid);
  6259. //UTC Date time
  6260. struct timeval tmnow;
  6261. struct tm *tm;
  6262. char buf[28];//, usec_buf[6];
  6263. gettimeofday(&tmnow, NULL);
  6264. time_t t;
  6265. t = time(NULL);
  6266. /*UTC time and date*/
  6267. tm = gmtime(&t);
  6268. if(dataType == ReadingContext_Sample_Clock)
  6269. {
  6270. struct tm *tmTarget;
  6271. struct timeb tbTarget;
  6272. tbTarget.time = mktime(tm);
  6273. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6274. tmTarget = gmtime(&tbTarget.time);
  6275. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6276. }
  6277. else
  6278. {
  6279. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6280. }
  6281. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6282. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6283. //********************************(1)Current.Import L1************************************************/
  6284. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6285. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6286. (dataType == ReadingContext_Trigger))
  6287. {
  6288. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6289. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6290. {
  6291. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6292. {
  6293. tempIndex = ((gun_index==2) ? 1: 0);
  6294. }
  6295. else
  6296. {
  6297. tempIndex = gun_index;
  6298. }
  6299. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6300. {
  6301. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6302. {
  6303. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6304. }
  6305. }
  6306. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6307. }
  6308. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6309. {
  6310. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6311. {
  6312. tempIndex = ((gun_index==2) ? 1: 0);
  6313. }
  6314. else
  6315. {
  6316. tempIndex = gun_index;
  6317. }
  6318. for (int index = 0; index < CCS_QUANTITY; index++)
  6319. {
  6320. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6321. {
  6322. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6323. }
  6324. }
  6325. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6326. }
  6327. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6328. {
  6329. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6330. {
  6331. tempIndex = ((gun_index==2) ? 1: 0);
  6332. }
  6333. else
  6334. {
  6335. tempIndex = gun_index;
  6336. }
  6337. for (int index = 0; index < GB_QUANTITY; index++)
  6338. {
  6339. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6340. {
  6341. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6342. }
  6343. }
  6344. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6345. }
  6346. else if(gunType[gun_index] == GUN_TYPE_DO)
  6347. {
  6348. tempIndex = gun_index;
  6349. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6350. {
  6351. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6352. {
  6353. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6354. }
  6355. }
  6356. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6357. }
  6358. else
  6359. {
  6360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6361. {
  6362. tempIndex = 2;
  6363. }
  6364. else
  6365. {
  6366. tempIndex = gun_index;
  6367. }
  6368. for (int index = 0; index < AC_QUANTITY; index++)
  6369. {
  6370. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6371. {
  6372. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6373. }
  6374. }
  6375. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6376. }
  6377. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6378. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6379. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6380. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6381. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6382. }
  6383. //********************************(2)Energy.Active.Import.Register ************************************************/
  6384. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6385. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6386. (dataType == ReadingContext_Trigger))
  6387. {
  6388. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6389. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6390. {
  6391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6392. {
  6393. tempIndex = ((gun_index==2) ? 1: 0);
  6394. }
  6395. else
  6396. {
  6397. tempIndex = gun_index;
  6398. }
  6399. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6400. {
  6401. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6402. {
  6403. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6404. }
  6405. }
  6406. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6407. }
  6408. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6409. {
  6410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6411. {
  6412. tempIndex = ((gun_index==2) ? 1: 0);
  6413. }
  6414. else
  6415. {
  6416. tempIndex = gun_index;
  6417. }
  6418. for (int index = 0; index < CCS_QUANTITY; index++)
  6419. {
  6420. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6421. {
  6422. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6423. }
  6424. }
  6425. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6426. }
  6427. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6428. {
  6429. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6430. {
  6431. tempIndex = ((gun_index==2) ? 1: 0);
  6432. }
  6433. else
  6434. {
  6435. tempIndex = gun_index;
  6436. }
  6437. for (int index = 0; index < GB_QUANTITY; index++)
  6438. {
  6439. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6440. {
  6441. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6442. }
  6443. }
  6444. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6445. }
  6446. else if(gunType[gun_index] == GUN_TYPE_DO)
  6447. {
  6448. tempIndex = gun_index;
  6449. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6450. {
  6451. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6452. {
  6453. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6454. }
  6455. }
  6456. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6457. }
  6458. else
  6459. {
  6460. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6461. {
  6462. tempIndex = 2;
  6463. }
  6464. else
  6465. {
  6466. tempIndex = gun_index;
  6467. }
  6468. for (int index = 0; index < AC_QUANTITY; index++)
  6469. {
  6470. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6471. {
  6472. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6473. }
  6474. }
  6475. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6476. }
  6477. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6478. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6479. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6480. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6481. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6482. }
  6483. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6484. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6485. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6486. (dataType == ReadingContext_Trigger))
  6487. {
  6488. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6489. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6490. {
  6491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6492. {
  6493. tempIndex = ((gun_index==2) ? 1: 0);
  6494. }
  6495. else
  6496. {
  6497. tempIndex = gun_index;
  6498. }
  6499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6500. {
  6501. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6502. {
  6503. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6504. }
  6505. } // END OF FOR CHAdeMO_QUANTITY
  6506. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6507. }
  6508. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6509. {
  6510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6511. {
  6512. tempIndex = ((gun_index==2) ? 1: 0);
  6513. }
  6514. else
  6515. {
  6516. tempIndex = gun_index;
  6517. }
  6518. for (int index = 0; index < CCS_QUANTITY; index++)
  6519. {
  6520. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6521. {
  6522. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6523. }
  6524. } // END OF CCS_QUANTITY
  6525. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6526. }
  6527. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6528. {
  6529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6530. {
  6531. tempIndex = ((gun_index==2) ? 1: 0);
  6532. }
  6533. else
  6534. {
  6535. tempIndex = gun_index;
  6536. }
  6537. for (int index = 0; index < GB_QUANTITY; index++)
  6538. {
  6539. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6540. {
  6541. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6542. }
  6543. } // END OF GB_QUANTITY
  6544. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6545. }
  6546. else if(gunType[gun_index] == GUN_TYPE_DO)
  6547. {
  6548. tempIndex = gun_index;
  6549. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6550. {
  6551. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6552. {
  6553. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6554. }
  6555. }
  6556. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6557. }
  6558. else
  6559. {
  6560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6561. {
  6562. tempIndex = 2;
  6563. }
  6564. else
  6565. {
  6566. tempIndex = gun_index;
  6567. }
  6568. for (int index = 0; index < AC_QUANTITY; index++)
  6569. {
  6570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6571. {
  6572. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6573. }
  6574. }
  6575. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6576. }
  6577. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6578. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6579. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6580. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6581. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6582. }
  6583. //********************************(4)Power.Active.Import************************************************/
  6584. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6585. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6586. (dataType == ReadingContext_Trigger))
  6587. {
  6588. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6589. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6590. {
  6591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6592. {
  6593. tempIndex = ((gun_index==2) ? 1: 0);
  6594. }
  6595. else
  6596. {
  6597. tempIndex = gun_index;
  6598. }
  6599. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6600. {
  6601. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6602. {
  6603. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6604. }
  6605. } // END OF FOR
  6606. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6607. }
  6608. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6609. {
  6610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6611. {
  6612. tempIndex = ((gun_index==2) ? 1: 0);
  6613. }
  6614. else
  6615. {
  6616. tempIndex = gun_index;
  6617. }
  6618. for (int index = 0; index < CCS_QUANTITY; index++)
  6619. {
  6620. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6621. {
  6622. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6623. }
  6624. }
  6625. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6626. }
  6627. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6628. {
  6629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6630. {
  6631. tempIndex = ((gun_index==2) ? 1: 0);
  6632. }
  6633. else
  6634. {
  6635. tempIndex = gun_index;
  6636. }
  6637. for (int index = 0; index < GB_QUANTITY; index++)
  6638. {
  6639. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6640. {
  6641. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6642. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6643. }
  6644. }
  6645. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6646. }
  6647. else if(gunType[gun_index] == GUN_TYPE_DO)
  6648. {
  6649. tempIndex = gun_index;
  6650. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6651. {
  6652. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6653. {
  6654. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6655. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6656. }
  6657. }
  6658. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6659. }
  6660. else
  6661. {
  6662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6663. {
  6664. tempIndex = 2;
  6665. }
  6666. else
  6667. {
  6668. tempIndex = gun_index;
  6669. }
  6670. for (int index = 0; index < AC_QUANTITY; index++)
  6671. {
  6672. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6673. {
  6674. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6675. }
  6676. }
  6677. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6678. }
  6679. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6680. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6681. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6682. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6683. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6684. }
  6685. //***********************************************(5)VOLTAGE L1******************************************************/
  6686. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6687. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6688. (dataType == ReadingContext_Trigger))
  6689. {
  6690. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6691. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6692. {
  6693. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6694. {
  6695. tempIndex = ((gun_index==2) ? 1: 0);
  6696. }
  6697. else
  6698. {
  6699. tempIndex = gun_index;
  6700. }
  6701. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6702. {
  6703. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6704. {
  6705. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6706. }
  6707. }
  6708. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6709. }
  6710. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6711. {
  6712. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6713. {
  6714. tempIndex = ((gun_index==2) ? 1: 0);
  6715. }
  6716. else
  6717. {
  6718. tempIndex = gun_index;
  6719. }
  6720. for (int index = 0; index < CCS_QUANTITY; index++)
  6721. {
  6722. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6723. {
  6724. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6725. }
  6726. }
  6727. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6728. }
  6729. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6730. {
  6731. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6732. {
  6733. tempIndex = ((gun_index==2) ? 1: 0);
  6734. }
  6735. else
  6736. {
  6737. tempIndex = gun_index;
  6738. }
  6739. for (int index = 0; index < GB_QUANTITY; index++)
  6740. {
  6741. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6742. {
  6743. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6744. }
  6745. }
  6746. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6747. }
  6748. else if(gunType[gun_index] == GUN_TYPE_DO)
  6749. {
  6750. tempIndex = gun_index;
  6751. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6752. {
  6753. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6754. {
  6755. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6756. }
  6757. }
  6758. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6759. }
  6760. else
  6761. {
  6762. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6763. {
  6764. tempIndex = 2;
  6765. }
  6766. else
  6767. {
  6768. tempIndex = gun_index;
  6769. }
  6770. for (int index = 0; index < AC_QUANTITY; index++)
  6771. {
  6772. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6773. {
  6774. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6775. }
  6776. }
  6777. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6778. }
  6779. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6780. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6781. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6782. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6783. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6784. }
  6785. //***********************************************(6)SOC******************************************************/
  6786. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6787. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6788. (dataType == ReadingContext_Trigger))
  6789. {
  6790. 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))
  6791. {
  6792. //idx_sample=5;
  6793. //sampledValue = NULL;
  6794. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6795. {
  6796. tempIndex = ((gun_index==2) ? 1: 0);
  6797. }
  6798. else
  6799. {
  6800. tempIndex = gun_index;
  6801. }
  6802. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6803. {
  6804. //tempIndex = ((gun_index==2) ? 1: 0);
  6805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6806. {
  6807. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6808. {
  6809. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6810. }
  6811. }
  6812. }
  6813. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6814. {
  6815. //tempIndex = ((gun_index==2) ? 1: 0);
  6816. for (int index = 0; index < CCS_QUANTITY; index++)
  6817. {
  6818. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6819. {
  6820. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6821. }
  6822. }
  6823. }
  6824. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6825. {
  6826. //tempIndex = ((gun_index==2) ? 1: 0);
  6827. for (int index = 0; index < GB_QUANTITY; index++)
  6828. {
  6829. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6830. {
  6831. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6832. }
  6833. }
  6834. }
  6835. else if(gunType[gun_index] == GUN_TYPE_DO)
  6836. {
  6837. //tempIndex = ((gun_index==2) ? 1: 0);
  6838. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6839. {
  6840. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6841. {
  6842. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6843. }
  6844. }
  6845. }
  6846. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6847. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6848. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6849. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6850. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6851. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6852. }
  6853. }
  6854. //********************************(7)Current.Import L2************************************************/
  6855. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6856. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6857. (dataType == ReadingContext_Trigger))
  6858. {
  6859. // Only for AC 3 phase
  6860. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6861. {
  6862. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6863. {
  6864. tempIndex = 2;
  6865. }
  6866. else
  6867. {
  6868. tempIndex = gun_index;
  6869. }
  6870. for (int index = 0; index < AC_QUANTITY; index++)
  6871. {
  6872. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6873. {
  6874. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6875. }
  6876. }
  6877. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6878. }
  6879. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6880. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6881. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6882. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6883. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6884. }
  6885. //********************************(8)Current.Import L3************************************************/
  6886. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6887. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6888. (dataType == ReadingContext_Trigger))
  6889. {
  6890. // Only for AC 3 phase
  6891. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6892. {
  6893. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6894. {
  6895. tempIndex = 2;
  6896. }
  6897. else
  6898. {
  6899. tempIndex = gun_index;
  6900. }
  6901. for (int index = 0; index < AC_QUANTITY; index++)
  6902. {
  6903. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6904. {
  6905. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6906. }
  6907. }
  6908. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6909. }
  6910. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6911. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6912. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6913. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6914. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6915. }
  6916. //***********************************************(9)VOLTAGE L2******************************************************/
  6917. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6918. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6919. (dataType == ReadingContext_Trigger))
  6920. {
  6921. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6922. {
  6923. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6924. {
  6925. tempIndex = 2;
  6926. }
  6927. else
  6928. {
  6929. tempIndex = gun_index;
  6930. }
  6931. for (int index = 0; index < AC_QUANTITY; index++)
  6932. {
  6933. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6934. {
  6935. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6936. }
  6937. }
  6938. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6939. }
  6940. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6941. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6942. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6943. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6944. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6945. }
  6946. //***********************************************(10)VOLTAGE L3******************************************************/
  6947. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6948. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6949. (dataType == ReadingContext_Trigger))
  6950. {
  6951. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6952. {
  6953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6954. {
  6955. tempIndex = 2;
  6956. }
  6957. else
  6958. {
  6959. tempIndex = gun_index;
  6960. }
  6961. for (int index = 0; index < AC_QUANTITY; index++)
  6962. {
  6963. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6964. {
  6965. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6966. }
  6967. }
  6968. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6969. }
  6970. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6971. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6972. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6973. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6974. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6975. }
  6976. //***********************************************(11)Current.Offered******************************************************/
  6977. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6978. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6979. (dataType == ReadingContext_Trigger))
  6980. {
  6981. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6982. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6983. {
  6984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6985. {
  6986. tempIndex = ((gun_index==2) ? 1: 0);
  6987. }
  6988. else
  6989. {
  6990. tempIndex = gun_index;
  6991. }
  6992. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6993. {
  6994. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6995. {
  6996. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6997. }
  6998. } // END OF FOR CHAdeMO_QUANTITY
  6999. }
  7000. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7001. {
  7002. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7003. {
  7004. tempIndex = ((gun_index==2) ? 1: 0);
  7005. }
  7006. else
  7007. {
  7008. tempIndex = gun_index;
  7009. }
  7010. for (int index = 0; index < CCS_QUANTITY; index++)
  7011. {
  7012. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7013. {
  7014. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  7015. }
  7016. } // END OF CCS_QUANTITY
  7017. }
  7018. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7019. {
  7020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7021. {
  7022. tempIndex = ((gun_index==2) ? 1: 0);
  7023. }
  7024. else
  7025. {
  7026. tempIndex = gun_index;
  7027. }
  7028. for (int index = 0; index < GB_QUANTITY; index++)
  7029. {
  7030. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7031. {
  7032. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  7033. }
  7034. } // END OF GB_QUANTITY
  7035. }
  7036. else if(gunType[gun_index] == GUN_TYPE_DO)
  7037. {
  7038. tempIndex = gun_index;
  7039. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7040. {
  7041. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7042. {
  7043. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  7044. }
  7045. }
  7046. }
  7047. else
  7048. {
  7049. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7050. {
  7051. tempIndex = 2;
  7052. }
  7053. else
  7054. {
  7055. tempIndex = gun_index;
  7056. }
  7057. for (int index = 0; index < AC_QUANTITY; index++)
  7058. {
  7059. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7060. {
  7061. uint16_t currentOffer;
  7062. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7063. {
  7064. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7065. }
  7066. else
  7067. {
  7068. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7069. }
  7070. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7071. }
  7072. }
  7073. }
  7074. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7075. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7076. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7077. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7078. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7079. }
  7080. //***********************************************(12)Power.Offered******************************************************/
  7081. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7082. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7083. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7084. {
  7085. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7086. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7087. {
  7088. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7089. {
  7090. tempIndex = ((gun_index==2) ? 1: 0);
  7091. }
  7092. else
  7093. {
  7094. tempIndex = gun_index;
  7095. }
  7096. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7097. {
  7098. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7099. {
  7100. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7101. }
  7102. } // END OF FOR CHAdeMO_QUANTITY
  7103. }
  7104. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7105. {
  7106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7107. {
  7108. tempIndex = ((gun_index==2) ? 1: 0);
  7109. }
  7110. else
  7111. {
  7112. tempIndex = gun_index;
  7113. }
  7114. for (int index = 0; index < CCS_QUANTITY; index++)
  7115. {
  7116. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7117. {
  7118. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7119. }
  7120. } // END OF CCS_QUANTITY
  7121. }
  7122. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7123. {
  7124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7125. {
  7126. tempIndex = ((gun_index==2) ? 1: 0);
  7127. }
  7128. else
  7129. {
  7130. tempIndex = gun_index;
  7131. }
  7132. for (int index = 0; index < GB_QUANTITY; index++)
  7133. {
  7134. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7135. {
  7136. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7137. }
  7138. } // END OF GB_QUANTITY
  7139. }
  7140. else if(gunType[gun_index] == GUN_TYPE_DO)
  7141. {
  7142. tempIndex = gun_index;
  7143. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7144. {
  7145. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7146. {
  7147. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7148. }
  7149. }
  7150. }
  7151. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7152. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7153. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7154. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7155. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7156. }
  7157. // Message create ====================================================================================================
  7158. if(TRUE)
  7159. {
  7160. json_object *MeterValueReq = json_object_new_object();
  7161. json_object *MeterValues = json_object_new_array();
  7162. json_object *sampledValues = json_object_new_array();
  7163. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7164. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7165. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7166. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7167. {
  7168. json_object *MeterValue = json_object_new_object();
  7169. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7170. {
  7171. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7172. {
  7173. json_object *sampledValue = json_object_new_object();
  7174. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7175. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7176. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7177. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7178. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7179. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7180. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7181. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7182. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7183. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7184. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7185. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7186. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7187. json_object_array_add(sampledValues, sampledValue);
  7188. }
  7189. }
  7190. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7191. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7192. json_object_array_add(MeterValues, MeterValue);
  7193. }
  7194. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7195. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7196. ,gun_index + 1
  7197. ,MESSAGE_TYPE_CALL
  7198. ,guid
  7199. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7200. json_object_put(MeterValueReq);
  7201. }
  7202. // Put request guid to hash map
  7203. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7204. 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*/)
  7205. {
  7206. result = PASS;
  7207. //DEBUG_INFO("MeterValues mapitem pass\n");
  7208. }
  7209. if((dataType != ReadingContext_Trigger) &&
  7210. (dataType != ReadingContext_Sample_Clock) &&
  7211. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7212. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7213. else
  7214. {
  7215. if(FirstHeartBeat)
  7216. LWS_Send(queuedata +2);
  7217. }
  7218. return result;
  7219. }
  7220. int sendLogStatusNotificationRequest(char *status)
  7221. {
  7222. mtrace();
  7223. int result = PASS;
  7224. char message[4096]={0};
  7225. char guid[37]={0};
  7226. char tempdata[128]={0};
  7227. json_object *LogStatusNotification = json_object_new_object();
  7228. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7229. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7230. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7231. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7232. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7233. random_uuid(guid);
  7234. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7235. json_object_put(LogStatusNotification);
  7236. LWS_Send(message);
  7237. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7238. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7239. {
  7240. result = PASS;
  7241. }
  7242. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7243. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7244. return result;
  7245. }
  7246. int sendSecurityEventNotificationRequest()
  7247. {
  7248. mtrace();
  7249. int result = PASS;
  7250. char message[4096]={0};
  7251. char guid[37]={0};
  7252. char tempdata[128]={0};
  7253. json_object *SecurityEventNotification = json_object_new_object();
  7254. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7255. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7256. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7257. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7258. random_uuid(guid);
  7259. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7260. json_object_put(SecurityEventNotification);
  7261. LWS_Send(message);
  7262. sprintf(tempdata, "SecurityEventNotification,0");
  7263. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7264. {
  7265. result = PASS;
  7266. }
  7267. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7268. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7269. return result;
  7270. }
  7271. int sendSignCertificateRequest()
  7272. {
  7273. mtrace();
  7274. int result = PASS;
  7275. char message[4096]={0};
  7276. char guid[37]={0};
  7277. char tempdata[128]={0};
  7278. json_object *SignCertificate = json_object_new_object();
  7279. DEBUG_INFO("sendSignCertificateRequest...\n");
  7280. // Read csr file content
  7281. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7282. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7283. char *line = NULL;
  7284. size_t len = 0;
  7285. while(getline(&line, &len, fp) != -1)
  7286. {
  7287. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7288. {
  7289. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7290. }
  7291. }
  7292. fclose(fp);
  7293. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7294. random_uuid(guid);
  7295. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7296. json_object_put(SignCertificate);
  7297. LWS_Send(message);
  7298. sprintf(tempdata, "SignCertificate,0");
  7299. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7300. {
  7301. result = PASS;
  7302. }
  7303. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7304. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7305. return result;
  7306. }
  7307. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7308. {
  7309. mtrace();
  7310. int result = PASS;
  7311. char message[110]={0};
  7312. char guid[37]={0};
  7313. char tempdata[65]={0};
  7314. json_object *FirmwareStatusNotification = json_object_new_object();
  7315. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7316. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7317. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7318. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7319. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7320. random_uuid(guid);
  7321. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7322. json_object_put(FirmwareStatusNotification);
  7323. LWS_Send(message);
  7324. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7325. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7326. {
  7327. result = PASS;
  7328. }
  7329. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7330. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7331. return result;
  7332. }
  7333. //==========================================
  7334. // send confirm routine
  7335. //==========================================
  7336. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7337. {
  7338. mtrace();
  7339. int result = FAIL;
  7340. char message[100]={0};
  7341. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7342. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7343. LWS_Send(message);
  7344. result = TRUE;
  7345. return result;
  7346. }
  7347. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7348. {
  7349. mtrace();
  7350. int result = FAIL;
  7351. char message[100]={0};
  7352. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7353. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7354. LWS_Send(message);
  7355. result = TRUE;
  7356. return result;
  7357. }
  7358. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7359. {
  7360. mtrace();
  7361. int result = FAIL;
  7362. char message[100]={0};
  7363. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7364. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7365. LWS_Send(message);
  7366. result = TRUE;
  7367. return result;
  7368. }
  7369. int sendClearCacheConfirmation(char *uuid,char *payload)
  7370. {
  7371. mtrace();
  7372. int result = FAIL;
  7373. char message[500]={0};
  7374. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7375. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7376. LWS_Send(message);
  7377. return result;
  7378. }
  7379. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7380. {
  7381. mtrace();
  7382. int result = FAIL;
  7383. char message[500]={0};
  7384. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7385. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7386. LWS_Send(message);
  7387. return result;
  7388. }
  7389. int sendDataTransferConfirmation(char *uuid,char *payload)
  7390. {
  7391. mtrace();
  7392. char statusStr[20]={0};
  7393. char dataStr[10]={0};
  7394. char sstr[20]={0};
  7395. int c = 0;
  7396. char *loc;
  7397. int result = FAIL;
  7398. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7399. /**********************status**************************/
  7400. loc = strstr(payload, "status");
  7401. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7402. c = 0;
  7403. while (loc[3+strlen("status")+c] != '\"')
  7404. {
  7405. sstr[c] = loc[3+strlen("status")+c];
  7406. c++;
  7407. }
  7408. sstr[c] = '\0';
  7409. strcpy(statusStr, sstr);
  7410. /**********************data**************************/
  7411. loc = strstr(payload, "data");
  7412. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7413. c = 0;
  7414. while (loc[3+strlen("data")+c] != '\"')
  7415. {
  7416. sstr[c] = loc[3+strlen("data")+c];
  7417. c++;
  7418. }
  7419. sstr[c] = '\0';
  7420. strcpy(dataStr, sstr);
  7421. return result;
  7422. }
  7423. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7424. {
  7425. mtrace();
  7426. int result = FAIL;
  7427. char message[1000]={0};
  7428. int CompositeScheduleIndex = 0;
  7429. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7430. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7431. if(nPeriod == 0)
  7432. {
  7433. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7434. {
  7435. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7436. ,MESSAGE_TYPE_CALLRESULT
  7437. ,uuid
  7438. ,payload
  7439. ,connectorIdInt);
  7440. }
  7441. else
  7442. {
  7443. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7444. ,MESSAGE_TYPE_CALLRESULT
  7445. ,uuid
  7446. ,payload
  7447. ,connectorIdInt
  7448. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7449. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7450. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7451. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7452. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7453. }
  7454. }
  7455. else
  7456. {
  7457. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7458. ,MESSAGE_TYPE_CALLRESULT
  7459. ,uuid
  7460. ,payload
  7461. ,connectorIdInt
  7462. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7463. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7464. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7465. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7466. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7467. {
  7468. if (idx_sample == 0)
  7469. {
  7470. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7471. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7472. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7473. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7474. }
  7475. else
  7476. {
  7477. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7478. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7479. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7480. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7481. }
  7482. }
  7483. sprintf(message + strlen(message), "]}}]");
  7484. }
  7485. LWS_Send(message);
  7486. result = TRUE;
  7487. return result;
  7488. }
  7489. int sendGetConfigurationConfirmation(char *uuid)
  7490. {
  7491. mtrace();
  7492. int result = FAIL;
  7493. int MaxKeySupported = 0;
  7494. int sentConfigurationNumber= 0;
  7495. int sentunConfigurationNumber= 0;
  7496. char message[1024*10]={0};
  7497. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7498. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7499. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7500. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7501. ,MESSAGE_TYPE_CALLRESULT
  7502. ,uuid );
  7503. //configuration key
  7504. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7505. {
  7506. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7507. {
  7508. if (sentConfigurationNumber == 0)
  7509. {
  7510. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7511. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7512. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7513. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7514. }
  7515. else
  7516. {
  7517. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7518. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7519. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7520. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7521. }
  7522. sentConfigurationNumber = sentConfigurationNumber + 1;
  7523. }
  7524. }
  7525. sprintf(message + strlen(message), "]");
  7526. if(UnknownKeynum != 0)
  7527. {
  7528. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7529. //unkown key
  7530. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7531. {
  7532. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7533. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7534. if(sentunConfigurationNumber == 0)
  7535. {
  7536. sprintf(message + strlen(message), "\"%s\""
  7537. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7538. }
  7539. else
  7540. {
  7541. sprintf(message + strlen(message), ",\"%s\""
  7542. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7543. }
  7544. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7545. }
  7546. sprintf(message + strlen(message), "]");
  7547. }
  7548. sprintf(message + strlen(message), "}]");
  7549. LWS_Send(message);
  7550. return result;
  7551. }
  7552. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7553. {
  7554. mtrace();
  7555. int result = FAIL;
  7556. char message[400]={0};
  7557. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7558. if(strcmp(payload,"")==0)
  7559. {
  7560. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7561. }
  7562. else
  7563. {
  7564. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7565. }
  7566. LWS_Send(message);
  7567. result = TRUE;
  7568. return result;
  7569. }
  7570. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7571. {
  7572. mtrace();
  7573. int result = FAIL;
  7574. char message[80]={0};
  7575. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7576. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7577. LWS_Send(message);
  7578. result = TRUE;
  7579. return result;
  7580. }
  7581. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7582. {
  7583. mtrace();
  7584. int result = FAIL;
  7585. char message[80]={0};
  7586. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7587. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7588. LWS_Send(message);
  7589. result = TRUE;
  7590. return result;
  7591. }
  7592. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7593. {
  7594. mtrace();
  7595. int result = FAIL;
  7596. char message[80]={0};
  7597. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7598. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7599. LWS_Send(message);
  7600. result = TRUE;
  7601. return result;
  7602. }
  7603. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7604. {
  7605. mtrace();
  7606. int result = FAIL;
  7607. char message[80]={0};
  7608. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7609. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7610. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7611. LWS_Send(message);
  7612. result = TRUE;
  7613. return result;
  7614. }
  7615. int sendResetConfirmation(char *uuid,char *payload)
  7616. {
  7617. mtrace();
  7618. int result = FAIL;
  7619. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7620. char message[80]={0};
  7621. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7622. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7623. LWS_Send(message);
  7624. result = TRUE;
  7625. return result;
  7626. }
  7627. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7628. {
  7629. mtrace();
  7630. int result = FAIL;
  7631. char message[500]={0};
  7632. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7633. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7634. LWS_Send(message);
  7635. result = TRUE;
  7636. return result;
  7637. }
  7638. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7639. {
  7640. mtrace();
  7641. int result = FAIL;
  7642. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7643. char message[80]={0};
  7644. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7645. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7646. LWS_Send(message);
  7647. result = TRUE;
  7648. return result;
  7649. }
  7650. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7651. {
  7652. mtrace();
  7653. int result = FAIL;
  7654. char message[80]={0};
  7655. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7656. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7657. LWS_Send(message);
  7658. result = TRUE;
  7659. return result;
  7660. }
  7661. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7662. {
  7663. mtrace();
  7664. int result = FAIL;
  7665. char message[80]={0};
  7666. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7667. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7668. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7669. LWS_Send(message);
  7670. result = TRUE;
  7671. return result;
  7672. }
  7673. int sendUpdateFirmwareConfirmation(char *uuid)
  7674. {
  7675. mtrace();
  7676. int result = FAIL;
  7677. char message[60]={0};
  7678. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7679. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7680. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7681. LWS_Send(message);
  7682. result = TRUE;
  7683. return result;
  7684. }
  7685. int sendCertificateSignedConfirmation(char *uuid)
  7686. {
  7687. mtrace();
  7688. int result = PASS;
  7689. char message[4096]={0};
  7690. json_object *CertificateSigned = json_object_new_object();
  7691. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7692. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7693. sprintf(message,"[%d,\"%s\",%s]"
  7694. ,MESSAGE_TYPE_CALLRESULT
  7695. ,uuid
  7696. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7697. json_object_put(CertificateSigned);
  7698. LWS_Send(message);
  7699. return result;
  7700. }
  7701. int sendDeleteCertificateConfirmation(char *uuid)
  7702. {
  7703. mtrace();
  7704. int result = PASS;
  7705. char message[4096]={0};
  7706. json_object *DeleteCertificate = json_object_new_object();
  7707. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7708. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7709. sprintf(message,"[%d,\"%s\",%s]"
  7710. ,MESSAGE_TYPE_CALLRESULT
  7711. ,uuid
  7712. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7713. json_object_put(DeleteCertificate);
  7714. LWS_Send(message);
  7715. return result;
  7716. }
  7717. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7718. {
  7719. mtrace();
  7720. int result = PASS;
  7721. char message[4096]={0};
  7722. json_object *ExtendedTriggerMessage = json_object_new_object();
  7723. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7724. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7725. sprintf(message,"[%d,\"%s\",%s]"
  7726. ,MESSAGE_TYPE_CALLRESULT
  7727. ,uuid
  7728. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7729. json_object_put(ExtendedTriggerMessage);
  7730. LWS_Send(message);
  7731. return result;
  7732. }
  7733. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7734. {
  7735. mtrace();
  7736. int result = PASS;
  7737. char message[4096]={0};
  7738. json_object *GetInstalledCertificateIds = json_object_new_object();
  7739. json_object *certificateHashDataDatas = json_object_new_array();
  7740. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7741. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7742. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7743. {
  7744. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7745. {
  7746. json_object *certificateHashData = json_object_new_object();
  7747. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7748. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7749. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7750. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7751. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7752. }
  7753. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7754. }
  7755. else
  7756. {
  7757. json_object_put(certificateHashDataDatas);
  7758. }
  7759. sprintf(message,"[%d,\"%s\",%s]"
  7760. ,MESSAGE_TYPE_CALLRESULT
  7761. ,uuid
  7762. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7763. json_object_put(GetInstalledCertificateIds);
  7764. LWS_Send(message);
  7765. return result;
  7766. }
  7767. int sendGetLogConfirmation(char *uuid)
  7768. {
  7769. mtrace();
  7770. int result = PASS;
  7771. char message[4096]={0};
  7772. json_object *GetLog = json_object_new_object();
  7773. DEBUG_INFO("sendGetLogConfirmation...\n");
  7774. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7775. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7776. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7777. sprintf(message,"[%d,\"%s\",%s]"
  7778. ,MESSAGE_TYPE_CALLRESULT
  7779. ,uuid
  7780. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7781. json_object_put(GetLog);
  7782. LWS_Send(message);
  7783. return result;
  7784. }
  7785. int sendInstallCertificateConfirmation(char *uuid)
  7786. {
  7787. mtrace();
  7788. int result = PASS;
  7789. char message[4096]={0};
  7790. json_object *InstallCertificate = json_object_new_object();
  7791. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7792. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7793. sprintf(message,"[%d,\"%s\",%s]"
  7794. ,MESSAGE_TYPE_CALLRESULT
  7795. ,uuid
  7796. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7797. json_object_put(InstallCertificate);
  7798. LWS_Send(message);
  7799. return result;
  7800. }
  7801. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7802. {
  7803. mtrace();
  7804. int result = PASS;
  7805. char message[4096]={0};
  7806. json_object *SignedUpdateFirmware = json_object_new_object();
  7807. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7808. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7809. sprintf(message,"[%d,\"%s\",%s]"
  7810. ,MESSAGE_TYPE_CALLRESULT
  7811. ,uuid
  7812. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7813. json_object_put(SignedUpdateFirmware);
  7814. LWS_Send(message);
  7815. return result;
  7816. }
  7817. int sendUnknownConfirmation(char *uuid)
  7818. {
  7819. mtrace();
  7820. int result = PASS;
  7821. char message[256]={0};
  7822. DEBUG_INFO("sendUnknownConfirmation...\n");
  7823. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7824. LWS_Send(message);
  7825. return result;
  7826. }
  7827. //==========================================
  7828. // Handle server request routine Start
  7829. //==========================================
  7830. int handleCancelReservationRequest(char *uuid, char *payload)
  7831. {
  7832. mtrace();
  7833. int result = FAIL;
  7834. int gunNO = 0;
  7835. int reservationIdInt = -1;
  7836. char comfirmstr[20];
  7837. DEBUG_INFO("handleCancelReservationRequest...\n");
  7838. json_object *CancelReservation;
  7839. CancelReservation = json_tokener_parse(payload);
  7840. if(!is_error(CancelReservation))
  7841. {
  7842. // Required data
  7843. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7844. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7845. }
  7846. json_object_put(CancelReservation);
  7847. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7848. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7849. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7850. if(reservationIdInt != -1)
  7851. {
  7852. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7853. //check Transaction active
  7854. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7855. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7856. {
  7857. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7858. {
  7859. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7860. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7861. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7862. {
  7863. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7864. }
  7865. else
  7866. {
  7867. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7868. }
  7869. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7870. goto end;
  7871. }
  7872. }
  7873. for (int index = 0; index < CCS_QUANTITY; index++)
  7874. {
  7875. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7876. {
  7877. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7878. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7879. if(gunType[2] == GUN_TYPE_CCS)
  7880. {
  7881. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7882. }
  7883. else
  7884. {
  7885. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7886. }
  7887. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7888. goto end;
  7889. }
  7890. }
  7891. for (int index = 0; index < GB_QUANTITY; index++)
  7892. {
  7893. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7894. {
  7895. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7896. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7897. if(gunType[2] == GUN_TYPE_GBT)
  7898. {
  7899. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7900. }
  7901. else
  7902. {
  7903. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7904. }
  7905. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7906. goto end;
  7907. }
  7908. }
  7909. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7910. {
  7911. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7912. {
  7913. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7914. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7915. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7916. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7917. goto end;
  7918. }
  7919. }
  7920. for (int index = 0; index < AC_QUANTITY; index++)
  7921. {
  7922. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7923. {
  7924. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7925. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7926. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7927. {
  7928. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7929. }
  7930. else
  7931. {
  7932. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7933. }
  7934. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7935. goto end;
  7936. }
  7937. }
  7938. }
  7939. //The reservationId does NOT match the reservationId
  7940. sendCancelReservationConfirmation(uuid, comfirmstr);
  7941. end:
  7942. // Fill in ocpp packet uuid
  7943. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7944. return result;
  7945. }
  7946. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7947. {
  7948. mtrace();
  7949. int result = FAIL;
  7950. int gunIndex = -1;
  7951. char typeStr[16]={0};
  7952. char comfirmstr[20];
  7953. int specificId = FALSE;
  7954. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7955. json_object *ChangeAvailability;
  7956. ChangeAvailability = json_tokener_parse(payload);
  7957. if(!is_error(ChangeAvailability))
  7958. {
  7959. // Required data
  7960. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7961. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7962. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7963. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7964. }
  7965. json_object_put(ChangeAvailability);
  7966. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7967. {
  7968. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7969. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7970. }
  7971. else if(gunIndex == 0)
  7972. {
  7973. for(int i=0; i < gunTotalNumber; i++)
  7974. {
  7975. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7976. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7977. }
  7978. }
  7979. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7980. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7981. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7982. {
  7983. specificId = TRUE;
  7984. }
  7985. if(specificId == FALSE)
  7986. goto end;
  7987. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7988. {
  7989. //----------------------gunIndex is 0 ------------------------------------------------//
  7990. if(gunIndex == 0)
  7991. {
  7992. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7993. {
  7994. for(int i=0; i < gunTotalNumber; i++)
  7995. {
  7996. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7997. {
  7998. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7999. {
  8000. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8001. {
  8002. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8003. goto end;
  8004. }
  8005. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8006. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8007. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8008. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8009. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8010. {
  8011. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8012. goto end;
  8013. }
  8014. }
  8015. }//END FOR CHAdeMO_QUANTITY
  8016. for (int index = 0; index < CCS_QUANTITY; index++)
  8017. {
  8018. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8019. {
  8020. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8021. {
  8022. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8023. goto end;
  8024. }
  8025. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8026. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8027. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8028. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8029. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8030. {
  8031. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8032. goto end;
  8033. }
  8034. }
  8035. }//END FOR CCS_QUANTITY
  8036. for (int index = 0; index < GB_QUANTITY; index++)
  8037. {
  8038. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8039. {
  8040. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8041. {
  8042. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8043. goto end;
  8044. }
  8045. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8046. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8047. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8048. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8049. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8050. {
  8051. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8052. goto end;
  8053. }
  8054. }
  8055. }// END FOR GB_QUANTITY
  8056. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8057. {
  8058. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8059. {
  8060. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8061. {
  8062. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8063. goto end;
  8064. }
  8065. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8066. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8067. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8068. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8069. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8070. {
  8071. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8072. goto end;
  8073. }
  8074. }
  8075. }// END FOR GENERAL_GUN_QUANTITY
  8076. for (int index = 0; index < AC_QUANTITY; index++)
  8077. {
  8078. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8079. {
  8080. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8081. {
  8082. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8083. goto end;
  8084. }
  8085. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8086. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8087. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8088. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8089. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8090. {
  8091. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8092. goto end;
  8093. }
  8094. }
  8095. }//END FOR AC_QUANTITY
  8096. }// END FOR gunTotalNumber
  8097. }
  8098. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8099. {
  8100. for(int i=0; i < gunTotalNumber; i++)
  8101. {
  8102. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8103. {
  8104. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8105. goto end;
  8106. }
  8107. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8108. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8109. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8110. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8111. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8112. {
  8113. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8114. goto end;
  8115. }
  8116. }
  8117. }
  8118. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8119. goto end;
  8120. }
  8121. //----------------------gunIndex is not 0 ------------------------------------------------//
  8122. //check Transaction active
  8123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8124. {
  8125. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8126. {
  8127. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8128. {
  8129. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8130. goto end;
  8131. }
  8132. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8133. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8134. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8135. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8136. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8137. {
  8138. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8139. goto end;
  8140. }
  8141. else
  8142. {
  8143. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8144. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8145. goto end;
  8146. }
  8147. }
  8148. }//END FOR CHAdeMO_QUANTITY
  8149. for (int index = 0; index < CCS_QUANTITY; index++)
  8150. {
  8151. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8152. {
  8153. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8154. {
  8155. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8156. goto end;
  8157. }
  8158. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8159. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8160. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8161. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8162. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8163. {
  8164. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8165. goto end;
  8166. }
  8167. else
  8168. {
  8169. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8170. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8171. goto end;
  8172. }
  8173. }
  8174. }//END FOR CCS_QUANTITY
  8175. for (int index = 0; index < GB_QUANTITY; index++)
  8176. {
  8177. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8178. {
  8179. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8180. {
  8181. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8182. goto end;
  8183. }
  8184. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8185. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8186. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8187. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8188. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8189. {
  8190. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8191. goto end;
  8192. }
  8193. else
  8194. {
  8195. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8196. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8197. goto end;
  8198. }
  8199. }
  8200. }// END FOR GB_QUANTITY
  8201. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8202. {
  8203. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8204. {
  8205. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8206. {
  8207. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8208. goto end;
  8209. }
  8210. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8211. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8212. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8213. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8214. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8215. {
  8216. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8217. goto end;
  8218. }
  8219. else
  8220. {
  8221. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8222. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8223. goto end;
  8224. }
  8225. }
  8226. }// END FOR GENERAL_GUN_QUANTITY
  8227. for (int index = 0; index < AC_QUANTITY; index++)
  8228. {
  8229. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8230. {
  8231. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8232. {
  8233. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8234. goto end;
  8235. }
  8236. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8237. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8238. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8239. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8240. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8241. {
  8242. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8243. goto end;
  8244. }
  8245. else
  8246. {
  8247. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8248. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8249. goto end;
  8250. }
  8251. }
  8252. }//END FOR AC_QUANTITY
  8253. }//END FOR AvailabilityTypeStr[Inoperative]
  8254. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8255. {
  8256. //----------------------gunIndex is 0 ------------------------------------------------//
  8257. if(gunIndex == 0)
  8258. {
  8259. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8260. {
  8261. for(int i=0; i < gunTotalNumber; i++)
  8262. {
  8263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8264. {
  8265. 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
  8266. {
  8267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8268. goto end;
  8269. }
  8270. }//END FOR CHAdeMO_QUANTITY
  8271. for (int index = 0; index < CCS_QUANTITY; index++)
  8272. {
  8273. 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
  8274. {
  8275. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8276. goto end;
  8277. }
  8278. }//END FOR CCS_QUANTITY
  8279. for (int index = 0; index < GB_QUANTITY; index++)
  8280. {
  8281. 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
  8282. {
  8283. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8284. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8285. goto end;
  8286. }
  8287. }// END FOR GB_QUANTITY
  8288. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8289. {
  8290. 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
  8291. {
  8292. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8294. goto end;
  8295. }
  8296. }// END FOR GENERAL_GUN_QUANTITY
  8297. for (int index = 0; index < AC_QUANTITY; index++)
  8298. {
  8299. 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
  8300. {
  8301. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8302. goto end;
  8303. }
  8304. }//END FOR CHAdeMO_QUANTITY
  8305. }// END FOR gunTotalNumber
  8306. }
  8307. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8308. {
  8309. for(int i=0; i < gunTotalNumber; i++)
  8310. {
  8311. for (int index = 0; index < AC_QUANTITY; index++)
  8312. {
  8313. 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
  8314. {
  8315. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8316. goto end;
  8317. }
  8318. }//END FOR CHAdeMO_QUANTITY
  8319. } // END FOR gunTotalNumber
  8320. }
  8321. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8322. goto end;
  8323. }
  8324. //----------------------gunIndex is not 0 ------------------------------------------------//
  8325. //check Transaction active
  8326. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8327. {
  8328. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8329. {
  8330. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8331. goto end;
  8332. }
  8333. }//END FOR CHAdeMO_QUANTITY
  8334. for (int index = 0; index < CCS_QUANTITY; index++)
  8335. {
  8336. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8337. {
  8338. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8339. goto end;
  8340. }
  8341. }//END FOR CCS_QUANTITY
  8342. for (int index = 0; index < GB_QUANTITY; index++)
  8343. {
  8344. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8345. {
  8346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8347. goto end;
  8348. }
  8349. }// END FOR GB_QUANTITY
  8350. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8351. {
  8352. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8353. {
  8354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8355. goto end;
  8356. }
  8357. }// END FOR GENERAL_GUN_QUANTITY
  8358. for (int index = 0; index < AC_QUANTITY; index++)
  8359. {
  8360. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8361. {
  8362. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8363. goto end;
  8364. }
  8365. }//END FOR AC_QUANTITY
  8366. }//END FOR AvailabilityTypeStr[Operative]
  8367. end:
  8368. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8369. {
  8370. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8371. }
  8372. else
  8373. {
  8374. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8375. }
  8376. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8377. {
  8378. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8379. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8380. }
  8381. else if(gunIndex == 0)
  8382. {
  8383. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8384. {
  8385. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8386. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8387. }
  8388. }
  8389. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8390. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8391. return result;
  8392. }
  8393. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8394. {
  8395. mtrace();
  8396. int valueInvalid = NO;
  8397. int result = FAIL;
  8398. char keystr[40]={0};
  8399. char valuestr[501]={0}; //value should be limited in 500 bytes
  8400. char comfirmstr[20]={0};
  8401. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8402. json_object *ChangeConfiguration;
  8403. ChangeConfiguration = json_tokener_parse(payload);
  8404. if(!is_error(ChangeConfiguration))
  8405. {
  8406. // Required data
  8407. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8408. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8409. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8410. {
  8411. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8412. }
  8413. else
  8414. {
  8415. valueInvalid = YES;
  8416. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8417. }
  8418. }
  8419. json_object_put(ChangeConfiguration);
  8420. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8421. {
  8422. DEBUG_ERROR("Payload is null or not accepted.\n");
  8423. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8424. }
  8425. else
  8426. {
  8427. int status = setKeyValue(keystr, valuestr);
  8428. switch(status)
  8429. {
  8430. case ConfigurationStatus_Accepted:
  8431. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8432. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8433. StoreConfigurationTable();
  8434. break;
  8435. case RebootRequired:
  8436. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8437. StoreConfigurationTable();
  8438. break;
  8439. case NotSupported:
  8440. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8441. break;
  8442. case ConfigurationStatus_Rejected:
  8443. default:
  8444. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8445. break;
  8446. }
  8447. }
  8448. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8449. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8450. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8451. {
  8452. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8453. SetOcppConnStatus(FALSE);
  8454. }
  8455. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8456. {
  8457. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8458. }
  8459. return result;
  8460. }
  8461. int handleClearCacheRequest(char *uuid, char *payload)
  8462. {
  8463. mtrace();
  8464. int result = FAIL;
  8465. char comfirmstr[20];
  8466. char rmFileCmd[100]={0};
  8467. struct stat stats;
  8468. DEBUG_INFO("handleClearCacheRequest...\n");
  8469. stat("/Storage/OCPP_PH", &stats);
  8470. // Check for directory existence
  8471. if (S_ISDIR(stats.st_mode) == 1)
  8472. {}
  8473. else
  8474. {
  8475. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8476. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8477. system(rmFileCmd);
  8478. }
  8479. if(OCPP_cleanLocalCache())
  8480. {
  8481. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8482. }
  8483. else
  8484. {
  8485. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8486. }
  8487. sendClearCacheConfirmation(uuid, comfirmstr);
  8488. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8489. return result;
  8490. }
  8491. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8492. {
  8493. mtrace();
  8494. int result = FAIL;
  8495. int resultRename;
  8496. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8497. char chargingProfilePurposeStr[26]={0};
  8498. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8499. char tempchargingProfilePurposeStr[26]={0};
  8500. char str[100]={0};
  8501. char fname[200]={0};
  8502. char comfirmstr[20]={0};
  8503. char word[1600]={0};
  8504. int clearflag = FALSE;
  8505. int chargingProfileIdIsNULL = FALSE;
  8506. int connectorIsNULL = FALSE;
  8507. int chargingProfilePurposeIsNULL = FALSE;
  8508. int stackLevelIsNULL = FALSE;
  8509. //int GotoEnd = FALSE;
  8510. FILE *fptr1, *fptr2;
  8511. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8512. int n_chargingProfile=0;
  8513. int isEmptyFile = FALSE;
  8514. char sLineWord[1600]={0};
  8515. char chargingProfiles[10][100]={0};
  8516. int ChargeProfileCount = 0;
  8517. int ch;
  8518. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8519. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8520. json_object *ClearChargingProfile;
  8521. ClearChargingProfile = json_tokener_parse(payload);
  8522. if(!is_error(ClearChargingProfile))
  8523. {
  8524. // Optional data
  8525. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8526. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8527. else
  8528. chargingProfileIdIsNULL = TRUE;
  8529. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8530. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8531. else
  8532. connectorIsNULL = TRUE;
  8533. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8534. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8535. else
  8536. chargingProfilePurposeIsNULL = TRUE;
  8537. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8538. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8539. else
  8540. stackLevelIsNULL = TRUE;
  8541. }
  8542. json_object_put(ClearChargingProfile);
  8543. if(connectorIsNULL == FALSE)
  8544. {
  8545. switch(connectorIdInt)
  8546. {
  8547. case 0:
  8548. if(chargingProfilePurposeIsNULL == TRUE)
  8549. {
  8550. int l = 0;
  8551. strcpy(fname, ChargePointMaxProfile_JSON);
  8552. if((access(fname,F_OK))!=-1)
  8553. {
  8554. strcpy(chargingProfiles[l], fname);
  8555. l = l + 1;
  8556. }
  8557. strcpy(fname, TxDefaultProfile_0_JSON);
  8558. if((access(fname,F_OK))!=-1)
  8559. {
  8560. strcpy(chargingProfiles[l], fname);
  8561. l = l + 1;
  8562. }
  8563. ChargeProfileCount = l;
  8564. }
  8565. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8566. {
  8567. strcpy(fname, ChargePointMaxProfile_JSON);
  8568. if((access(fname,F_OK))!=-1)
  8569. {
  8570. strcpy(chargingProfiles[0], fname);
  8571. ChargeProfileCount = 1;
  8572. }
  8573. }
  8574. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8575. {
  8576. strcpy(fname, TxDefaultProfile_0_JSON);
  8577. if((access(fname,F_OK))!=-1)
  8578. {
  8579. strcpy(chargingProfiles[0], fname);
  8580. ChargeProfileCount = 1;
  8581. }
  8582. }
  8583. break;
  8584. default:
  8585. if(chargingProfilePurposeIsNULL == TRUE)
  8586. {
  8587. int m = 0;
  8588. memset(fname, 0, ARRAY_SIZE(fname));
  8589. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8590. if((access(fname,F_OK))!=-1)
  8591. {
  8592. strcpy(chargingProfiles[m], fname);
  8593. m = m + 1;
  8594. }
  8595. memset(fname, 0, ARRAY_SIZE(fname));
  8596. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8597. if((access(fname,F_OK))!=-1)
  8598. {
  8599. strcpy(chargingProfiles[m], fname);
  8600. m = m + 1;
  8601. }
  8602. ChargeProfileCount = m;
  8603. }
  8604. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8605. {
  8606. //strcpy(fname, TxDefaultProfile_1_JSON);
  8607. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8608. if((access(fname,F_OK))!=-1)
  8609. {
  8610. strcpy(chargingProfiles[0], fname);
  8611. ChargeProfileCount = 1;
  8612. }
  8613. }
  8614. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8615. {
  8616. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8617. if((access(fname,F_OK))!=-1)
  8618. {
  8619. strcpy(chargingProfiles[0], fname);
  8620. ChargeProfileCount = 1;
  8621. }
  8622. //strcpy(fname, TxProfile_1_JSON);
  8623. }
  8624. //strcpy(fname, ChargePointMaxProfile_JSON );
  8625. break;
  8626. }
  8627. }
  8628. else // Check all Charging Profiles
  8629. {
  8630. int i = 0;
  8631. char fnametemp[200]={0};
  8632. ChargeProfileCount = 0;
  8633. //Check ChargePointMaxProfile.json exit
  8634. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8635. {
  8636. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8637. i = i + 1;
  8638. }
  8639. //Check TxDefaultProfile_0.json exit
  8640. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8641. {
  8642. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8643. i = i + 1;
  8644. }
  8645. //Check TxDefaultProfile_%d.json
  8646. for(int j=1; j <= gunTotalNumber; j++)
  8647. {
  8648. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8649. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8650. if((access(fnametemp,F_OK))!=-1)
  8651. {
  8652. strcpy(chargingProfiles[i], fnametemp);
  8653. i = i + 1;
  8654. }
  8655. }
  8656. //Check TxProfile_%d.json
  8657. for(int j=1; j <= gunTotalNumber; j++)
  8658. {
  8659. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8660. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8661. if((access(fnametemp,F_OK))!=-1)
  8662. {
  8663. strcpy(chargingProfiles[i], fnametemp);
  8664. i = i + 1;
  8665. }
  8666. }
  8667. ChargeProfileCount = i;
  8668. }// End connectorIsNULL is TRUE
  8669. if(ChargeProfileCount == 0)
  8670. {
  8671. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8672. goto end;
  8673. }
  8674. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8675. {
  8676. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8677. goto end;
  8678. }
  8679. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8680. {
  8681. memset(str, 0, ARRAY_SIZE(str));
  8682. // clear temp file
  8683. sprintf(str,"rm -f %s",temp);
  8684. system(str);
  8685. for(int k=0; k < ChargeProfileCount; k++)
  8686. {
  8687. memset(str, 0, ARRAY_SIZE(str));
  8688. //clear file in C
  8689. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8690. system(str);
  8691. }
  8692. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8693. goto end;
  8694. }
  8695. else if(connectorIsNULL == TRUE)
  8696. {
  8697. for(int k=0; k < ChargeProfileCount; k++)
  8698. {
  8699. fptr1 = fopen(chargingProfiles[k], "r");
  8700. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8701. //Check Charging Profile Count
  8702. while(fscanf(fptr1, "%s", word) != EOF)
  8703. {
  8704. //DEBUG_INFO("word=%s\n",word);
  8705. if(strstr(word, "chargingProfileId")!= NULL)
  8706. {
  8707. //DEBUG_INFO("test chargingProfileId \n");
  8708. n_chargingProfile = n_chargingProfile + 1;
  8709. //DEBUG_INFO("chargingProfileId Found\n");
  8710. }
  8711. }
  8712. rewind(fptr1);
  8713. //search Charging Profile Element
  8714. //int i= 0;
  8715. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8716. {
  8717. json_object *tmpProfilee;
  8718. tmpProfilee = json_tokener_parse(sLineWord);
  8719. if(!is_error(tmpProfilee))
  8720. {
  8721. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8722. {
  8723. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8724. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8725. }
  8726. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8727. {
  8728. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8729. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8730. }
  8731. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8732. {
  8733. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8734. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8735. }
  8736. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8737. {
  8738. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8739. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8740. }
  8741. }
  8742. json_object_put(tmpProfilee);
  8743. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8744. {
  8745. //------- not write to fptr2-------//
  8746. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8747. //clearflag = TRUE;
  8748. }
  8749. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8750. {
  8751. //------- not write to fptr2-------//
  8752. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8753. }
  8754. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8755. {
  8756. //------- not write to fptr2-------//
  8757. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8758. }
  8759. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8760. {
  8761. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8762. }
  8763. else
  8764. {
  8765. fprintf(fptr2, sLineWord);//writing data into file
  8766. }
  8767. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8768. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8769. if(clearflag == TRUE)
  8770. {
  8771. fclose(fptr1);
  8772. fclose(fptr2);
  8773. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8774. system(str);
  8775. // clear temp file
  8776. sprintf(str,"rm -f %s",temp);
  8777. system(str);
  8778. }
  8779. else
  8780. {
  8781. fclose(fptr1);
  8782. fclose(fptr2);
  8783. memset(str, 0, ARRAY_SIZE(str));
  8784. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8785. system(str);
  8786. resultRename = rename(temp, chargingProfiles[k]);
  8787. if(resultRename == 0)
  8788. {
  8789. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8790. }
  8791. else
  8792. {
  8793. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8794. }
  8795. if(comfirmstr[0]== 0)
  8796. {
  8797. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8798. }
  8799. //Check chargingProfile is empty file
  8800. /*------ Read the file ----------------*/
  8801. fptr1=fopen(chargingProfiles[k],"r");
  8802. ch=fgetc(fptr1);
  8803. rewind(fptr1);
  8804. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8805. if(ch!=EOF)
  8806. {
  8807. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8808. {
  8809. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8810. if(sLineWord[0]=='\0')
  8811. {
  8812. isEmptyFile = TRUE;
  8813. break;
  8814. }
  8815. else
  8816. {
  8817. isEmptyFile = FALSE;
  8818. break;
  8819. }
  8820. }
  8821. }
  8822. else
  8823. isEmptyFile = TRUE;
  8824. fclose(fptr1);
  8825. if(isEmptyFile == TRUE)
  8826. {
  8827. memset(str, 0, ARRAY_SIZE(str));
  8828. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8829. system(str);
  8830. }
  8831. }
  8832. }// End of while(int k=0; k < ChargePointCount; k++)
  8833. }
  8834. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8835. {
  8836. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8837. for(int k=0; k < ChargeProfileCount; k++)
  8838. {
  8839. fptr1 = fopen(chargingProfiles[k], "r");
  8840. fptr2 = fopen(temp, "w+");
  8841. //Check Charging Profile Count
  8842. while(fscanf(fptr1, "%s", word) != EOF)
  8843. {
  8844. //DEBUG_INFO("word=%s\n",word);
  8845. if(strstr(word, "chargingProfileId")!= NULL)
  8846. {
  8847. n_chargingProfile = n_chargingProfile + 1;
  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((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8888. {
  8889. //------- not write to fptr2-------//
  8890. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8891. }
  8892. else if(stackLevelIsNULL == TRUE)
  8893. {
  8894. //Clear Whole File
  8895. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8896. clearflag = TRUE;
  8897. break;
  8898. }
  8899. else
  8900. {
  8901. fprintf(fptr2, sLineWord);//writing data into file
  8902. }
  8903. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8904. }
  8905. if(clearflag == TRUE)
  8906. {
  8907. fclose(fptr1);
  8908. fclose(fptr2);
  8909. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8910. system(str);
  8911. // clear temp file
  8912. sprintf(str,"rm -f %s",temp);
  8913. system(str);
  8914. }
  8915. else
  8916. {
  8917. fclose(fptr1);
  8918. fclose(fptr2);
  8919. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8920. system(str);
  8921. resultRename = rename(temp, chargingProfiles[k]);
  8922. if(resultRename == 0)
  8923. {
  8924. DEBUG_INFO("File ChargingProfile renamed successfully");
  8925. }
  8926. else
  8927. {
  8928. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8929. }
  8930. if(comfirmstr[0]== 0)
  8931. {
  8932. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8933. }
  8934. //Check chargingProfile is empty file
  8935. /*------ Read the file ----------------*/
  8936. fptr1=fopen(chargingProfiles[k],"r");
  8937. ch=fgetc(fptr1);
  8938. rewind(fptr1);
  8939. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8940. if(ch!=EOF)
  8941. {
  8942. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8943. {
  8944. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8945. if(sLineWord[0]=='\0')
  8946. {
  8947. isEmptyFile = TRUE;
  8948. break;
  8949. }
  8950. else
  8951. {
  8952. isEmptyFile = FALSE;
  8953. break;
  8954. }
  8955. }
  8956. }
  8957. else
  8958. isEmptyFile = TRUE;
  8959. fclose(fptr1);
  8960. if(isEmptyFile == TRUE)
  8961. {
  8962. memset(str, 0, ARRAY_SIZE(str));
  8963. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8964. system(str);
  8965. }
  8966. /*------- End of reading ---------------*/
  8967. }
  8968. } // while(int k=0; k < ChargeProfileCount; k++)
  8969. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8970. end:
  8971. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8972. {
  8973. if(connectorIdInt == 0)
  8974. {
  8975. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8976. {
  8977. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8978. }
  8979. }
  8980. else
  8981. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8982. }
  8983. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8984. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8985. return result;
  8986. }
  8987. void createFirmwareVersionByDataTransfer(void)
  8988. {
  8989. json_object *FirmwareDataTransfer = json_object_new_object();
  8990. // AC & DC model
  8991. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8992. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8993. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8994. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8995. // DC model
  8996. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8997. {
  8998. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8999. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9000. (gunType[3] != GUN_TYPE_UNKNOWN))
  9001. {
  9002. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9003. }
  9004. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9005. {
  9006. // DS DM DW
  9007. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9008. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9009. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9010. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9011. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9012. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9013. }
  9014. else
  9015. {
  9016. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9017. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9018. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9019. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9020. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9021. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9022. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9023. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9024. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9025. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9026. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9027. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9028. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9029. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9030. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9031. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9032. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9033. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9034. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9035. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9036. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9037. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9038. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9039. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9040. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9041. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9042. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9043. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9044. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9045. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9046. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9047. }
  9048. }
  9049. // 4G model
  9050. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9051. {
  9052. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9053. }
  9054. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9055. json_object_put(FirmwareDataTransfer);
  9056. }
  9057. int handleDataTransferRequest(char *uuid, char *payload)
  9058. {
  9059. mtrace();
  9060. json_object *response = json_object_new_object();
  9061. int result = FAIL;
  9062. char tempvendorId[255]={0};
  9063. char tempmessageId[50]={0};
  9064. char tempdata[1024]={0};
  9065. char message[2048]={0};
  9066. DEBUG_INFO("handleDataTransferRequest...\n");
  9067. if((uuid != NULL) && (payload != NULL))
  9068. {
  9069. json_object *DataTransfer;
  9070. DataTransfer = json_tokener_parse(payload);
  9071. if(!is_error(DataTransfer))
  9072. {
  9073. // Required data
  9074. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9075. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9076. // Optional data
  9077. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9078. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9079. if(json_object_object_get(DataTransfer, "data") != NULL)
  9080. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9081. result = PASS;
  9082. }
  9083. json_object_put(DataTransfer);
  9084. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9085. {
  9086. // Send all moudle firmware version on EVSE
  9087. createFirmwareVersionByDataTransfer();
  9088. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9089. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9090. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9091. json_object_put(response);
  9092. }
  9093. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9094. {
  9095. system("/usr/bin/run_tmate_restart.sh &");
  9096. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9097. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9098. json_object_put(response);
  9099. }
  9100. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9101. {
  9102. json_object *data;
  9103. data = json_tokener_parse(tempdata);
  9104. if(!is_error(data))
  9105. {
  9106. 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))
  9107. {
  9108. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9109. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9110. if(json_object_object_get(data, "SOC") != NULL)
  9111. {
  9112. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9113. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9114. }
  9115. if(json_object_object_get(data, "Energy") != NULL)
  9116. {
  9117. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9118. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9119. }
  9120. if(json_object_object_get(data, "Duration") != NULL)
  9121. {
  9122. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9123. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9124. }
  9125. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9126. }
  9127. else
  9128. {
  9129. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9130. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9131. }
  9132. }
  9133. else
  9134. {
  9135. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9136. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9137. }
  9138. json_object_put(data);
  9139. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9140. json_object_put(response);
  9141. }
  9142. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9143. {
  9144. json_object *data;
  9145. data = json_tokener_parse(tempdata);
  9146. if(!is_error(data))
  9147. {
  9148. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9149. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9150. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9151. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9152. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9153. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9154. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9155. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9156. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9157. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9158. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9159. }
  9160. else
  9161. {
  9162. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9163. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9164. }
  9165. json_object_put(data);
  9166. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9167. json_object_put(response);
  9168. }
  9169. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9170. {
  9171. json_object *data;
  9172. data = json_tokener_parse(tempdata);
  9173. if(!is_error(data))
  9174. {
  9175. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9176. if(json_object_object_get(data, "idToken") != NULL)
  9177. {
  9178. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9179. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9180. }
  9181. if(json_object_object_get(data, "price") != NULL)
  9182. {
  9183. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9184. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9185. }
  9186. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9187. }
  9188. else
  9189. {
  9190. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9191. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9192. }
  9193. json_object_put(data);
  9194. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9195. json_object_put(response);
  9196. }
  9197. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9198. {
  9199. json_object *data;
  9200. data = json_tokener_parse(tempdata);
  9201. if(!is_error(data))
  9202. {
  9203. if(json_object_object_get(data, "txId") != NULL)
  9204. {
  9205. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9206. for(int idx = 0;idx<gunTotalNumber;idx++)
  9207. {
  9208. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9209. {
  9210. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9211. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9212. if(json_object_object_get(data, "description") != NULL)
  9213. {
  9214. // California pricing V1.0
  9215. DEBUG_INFO("California pricing V1.0\n");
  9216. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9217. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9218. }
  9219. else
  9220. {
  9221. // California pricing V1.1
  9222. DEBUG_INFO("California pricing V1.1\n");
  9223. if(json_object_object_get(data, "timestamp") != NULL)
  9224. {
  9225. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9226. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9227. }
  9228. if(json_object_object_get(data, "meterValue") != NULL)
  9229. {
  9230. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9231. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9232. }
  9233. if(json_object_object_get(data, "cost") != NULL)
  9234. {
  9235. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9236. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9237. }
  9238. if(json_object_object_get(data, "state") != NULL)
  9239. {
  9240. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9241. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9242. }
  9243. if(json_object_object_get(data, "chargingPrice") != NULL)
  9244. {
  9245. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9246. {
  9247. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9248. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9249. }
  9250. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9251. {
  9252. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9253. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9254. }
  9255. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9256. {
  9257. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9258. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9259. }
  9260. }
  9261. if(json_object_object_get(data, "idlePrice") != NULL)
  9262. {
  9263. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9264. {
  9265. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9266. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9267. }
  9268. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9269. {
  9270. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9271. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9272. }
  9273. }
  9274. if(json_object_object_get(data, "nextPeriod") != NULL)
  9275. {
  9276. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9277. {
  9278. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9279. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9280. }
  9281. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9282. {
  9283. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9284. {
  9285. 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")));
  9286. 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"));
  9287. }
  9288. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9289. {
  9290. 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")));
  9291. 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"));
  9292. }
  9293. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9294. {
  9295. 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")));
  9296. 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"));
  9297. }
  9298. }
  9299. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9300. {
  9301. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9302. {
  9303. 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")));
  9304. 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"));
  9305. }
  9306. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9307. {
  9308. 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")));
  9309. 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"));
  9310. }
  9311. }
  9312. }
  9313. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9314. {
  9315. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9316. {
  9317. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9318. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9319. }
  9320. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9321. {
  9322. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9323. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9324. }
  9325. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9326. {
  9327. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9328. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9329. }
  9330. }
  9331. }
  9332. }
  9333. }
  9334. }
  9335. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9336. }
  9337. else
  9338. {
  9339. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9340. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9341. }
  9342. json_object_put(data);
  9343. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9344. json_object_put(response);
  9345. }
  9346. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9347. {
  9348. json_object *data;
  9349. data = json_tokener_parse(tempdata);
  9350. if(!is_error(data))
  9351. {
  9352. if(json_object_object_get(data, "txId") != NULL)
  9353. {
  9354. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9355. for(int idx = 0;idx<gunTotalNumber;idx++)
  9356. {
  9357. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9358. {
  9359. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9360. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9361. if(json_object_object_get(data, "description") != NULL)
  9362. {
  9363. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9364. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9365. }
  9366. }
  9367. }
  9368. }
  9369. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9370. }
  9371. else
  9372. {
  9373. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9374. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9375. }
  9376. json_object_put(data);
  9377. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9378. json_object_put(response);
  9379. }
  9380. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9381. {
  9382. json_object *data;
  9383. data = json_tokener_parse(tempdata);
  9384. if(!is_error(data))
  9385. {
  9386. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9387. if(json_object_object_get(data, "Content_Type") != NULL)
  9388. {
  9389. 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))
  9390. {
  9391. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9392. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9393. {
  9394. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9395. }
  9396. }
  9397. else
  9398. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9399. }
  9400. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9401. }
  9402. else
  9403. {
  9404. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9405. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9406. }
  9407. json_object_put(data);
  9408. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9409. json_object_put(response);
  9410. }
  9411. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9412. {
  9413. json_object *data;
  9414. data = json_tokener_parse(tempdata);
  9415. if(!is_error(data))
  9416. {
  9417. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9418. if(json_object_object_get(data, "ConnectorId") != NULL)
  9419. {
  9420. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9421. }
  9422. if(json_object_object_get(data, "SerialNo") != NULL)
  9423. {
  9424. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9425. }
  9426. if(json_object_object_get(data, "Page_Index") != NULL)
  9427. {
  9428. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9429. }
  9430. if(json_object_object_get(data, "Duration") != NULL)
  9431. {
  9432. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9433. }
  9434. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9435. }
  9436. else
  9437. {
  9438. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9439. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9440. }
  9441. json_object_put(data);
  9442. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9443. json_object_put(response);
  9444. }
  9445. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9446. {
  9447. json_object *data;
  9448. data = json_tokener_parse(tempdata);
  9449. if(!is_error(data))
  9450. {
  9451. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9452. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9453. {
  9454. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9455. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9456. else
  9457. {
  9458. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9459. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9460. }
  9461. }
  9462. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9463. {
  9464. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9465. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9466. else
  9467. {
  9468. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9469. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9470. }
  9471. }
  9472. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9473. {
  9474. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9475. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9476. else
  9477. {
  9478. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9479. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9480. }
  9481. }
  9482. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9483. {
  9484. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9485. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9486. else
  9487. {
  9488. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9489. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9490. }
  9491. }
  9492. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9493. {
  9494. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9495. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9496. else
  9497. {
  9498. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9499. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9500. }
  9501. }
  9502. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9503. {
  9504. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9505. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9506. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9507. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9508. else
  9509. {
  9510. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9511. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9512. }
  9513. }
  9514. if(json_object_object_get(data, "isAuthentication") != NULL)
  9515. {
  9516. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9517. {
  9518. case 0:
  9519. case 1:
  9520. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9521. break;
  9522. default:
  9523. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9524. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9525. break;
  9526. }
  9527. }
  9528. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9529. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9530. }
  9531. else
  9532. {
  9533. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9534. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9535. }
  9536. json_object_put(data);
  9537. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9538. json_object_put(response);
  9539. }
  9540. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9541. {
  9542. json_object *data;
  9543. data = json_tokener_parse(tempdata);
  9544. if(!is_error(data))
  9545. {
  9546. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9547. if(json_object_object_get(data, "stationName") != NULL)
  9548. {
  9549. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9550. }
  9551. else
  9552. {
  9553. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9554. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9555. }
  9556. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9557. {
  9558. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9559. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9560. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9561. }
  9562. }
  9563. else
  9564. {
  9565. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9566. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9567. }
  9568. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9569. json_object_put(response);
  9570. }
  9571. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9572. {
  9573. json_object *data;
  9574. data = json_tokener_parse(tempdata);
  9575. if(!is_error(data))
  9576. {
  9577. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9578. if(json_object_object_get(data, "weatherId") != NULL)
  9579. {
  9580. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9581. }
  9582. else
  9583. {
  9584. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9585. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9586. }
  9587. if(json_object_object_get(data, "Temperature") != NULL)
  9588. {
  9589. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9590. }
  9591. else
  9592. {
  9593. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9594. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9595. }
  9596. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9597. {
  9598. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9599. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9600. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9601. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9602. }
  9603. }
  9604. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9605. {
  9606. json_object *data;
  9607. data = json_tokener_parse(tempdata);
  9608. if(!is_error(data))
  9609. {
  9610. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9611. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9612. {
  9613. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9614. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9615. }
  9616. else
  9617. {
  9618. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9619. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9620. }
  9621. }
  9622. else
  9623. {
  9624. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9625. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9626. }
  9627. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9628. json_object_put(response);
  9629. }
  9630. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9631. {
  9632. json_object *data;
  9633. data = json_tokener_parse(tempdata);
  9634. if(!is_error(data))
  9635. {
  9636. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9637. {
  9638. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9639. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9640. if(gun_index < gunTotalNumber)
  9641. {
  9642. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9643. {
  9644. json_object *responsedata = json_object_new_object();
  9645. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9646. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9647. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9648. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9649. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9650. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9651. }
  9652. else
  9653. {
  9654. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9655. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9656. }
  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("ConnectorId is invalid."));
  9662. }
  9663. }
  9664. else
  9665. {
  9666. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9667. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9668. }
  9669. }
  9670. else
  9671. {
  9672. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9673. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9674. }
  9675. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9676. json_object_put(response);
  9677. }
  9678. else
  9679. {
  9680. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9681. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9682. }
  9683. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9684. json_object_put(response);
  9685. }
  9686. else
  9687. {
  9688. // Can not find valid message id
  9689. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9690. }
  9691. }
  9692. else
  9693. {
  9694. // Payload is null
  9695. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9696. }
  9697. LWS_Send(message);
  9698. return result;
  9699. }
  9700. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9701. {
  9702. mtrace();
  9703. int result = FAIL;
  9704. int connectorIdInt, durationInt;
  9705. char chargingRateUnitStr[4]={0};
  9706. char comfirmstr[20];
  9707. int confirmPeriods = 0;
  9708. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9709. json_object *GetCompositeSchedule;
  9710. GetCompositeSchedule = json_tokener_parse(payload);
  9711. if(!is_error(GetCompositeSchedule))
  9712. {
  9713. // Required data
  9714. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9715. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9716. else
  9717. connectorIdInt = -1;
  9718. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9719. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9720. else
  9721. durationInt = 86400;
  9722. // Optional data
  9723. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9724. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9725. }
  9726. json_object_put(GetCompositeSchedule);
  9727. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9728. if((connectorIdInt == 0) ||
  9729. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9730. {
  9731. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9732. struct StructChargingProfile tmpProfile[1];
  9733. if(strstr(chargingRateUnitStr, "W") != NULL)
  9734. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9735. else
  9736. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9737. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9738. {
  9739. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9740. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9741. }
  9742. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9743. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9744. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9745. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9746. {
  9747. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9748. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9749. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9750. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9751. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9752. {
  9753. confirmPeriods = idx;
  9754. break;
  9755. }
  9756. }
  9757. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9758. {
  9759. confirmPeriods += 1;
  9760. }
  9761. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9762. }
  9763. else
  9764. {
  9765. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9766. }
  9767. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9768. return result;
  9769. }
  9770. int handleGetConfigurationRequest(char *uuid, char *payload)
  9771. {
  9772. mtrace();
  9773. int result = FAIL;
  9774. int MaxKeySupported = 0;
  9775. int n_keys = 0;
  9776. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9777. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9778. json_object *GetConfiguration;
  9779. GetConfiguration = json_tokener_parse(payload);
  9780. if(!is_error(GetConfiguration))
  9781. {
  9782. // Optional data
  9783. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9784. {
  9785. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9786. {
  9787. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9788. n_keys = idx + 1;
  9789. }
  9790. }
  9791. }
  9792. json_object_put(GetConfiguration);
  9793. UnknownKeynum = 0;
  9794. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9795. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9796. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9797. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9798. if(n_keys != 0)
  9799. {
  9800. for(int i=0;i<n_keys;i++)
  9801. {
  9802. getKeyValue(requestKey[i]);
  9803. }
  9804. }
  9805. else
  9806. {
  9807. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9808. getKeyValue("");
  9809. }
  9810. processUnkownKey();
  9811. sendGetConfigurationConfirmation(uuid);
  9812. return result;
  9813. }
  9814. static char fnamePlusPath[100]={0};
  9815. static char fnamePWithNoPath[60]={0};
  9816. void checkUploadLog(void)
  9817. {
  9818. FILE *fp;
  9819. /* Open the command for reading. */
  9820. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9821. if (fp == NULL) {
  9822. DEBUG_WARN("Failed to run command\n" );
  9823. exit(1);
  9824. }
  9825. int ftppathlen = 0;
  9826. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9827. int i = 0;
  9828. /* Read the output a line at a time - output it. */
  9829. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9830. if(i==0)
  9831. {
  9832. ftppathlen = strlen(fnamePlusPath);
  9833. DEBUG_INFO("%s\n", fnamePlusPath);
  9834. fnamePlusPath[ftppathlen]='\0';
  9835. break;
  9836. }
  9837. i= i+1;
  9838. }
  9839. /* close */
  9840. pclose(fp);
  9841. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9842. {
  9843. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9844. {
  9845. fnamePlusPath[k]='\0';
  9846. }
  9847. }
  9848. i=1;
  9849. //char fname[60]={0};
  9850. while(i < ftppathlen)
  9851. {
  9852. int len=ftppathlen-i;
  9853. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9854. {
  9855. DEBUG_INFO("compare '/' all right\n");
  9856. break;
  9857. }
  9858. i=i+1;
  9859. }
  9860. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9861. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9862. fnamePWithNoPath[i+1] = '\0';
  9863. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9864. {
  9865. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9866. {
  9867. fnamePWithNoPath[j]='\0';
  9868. }
  9869. }
  9870. FILE* fp1 = fopen(fnamePlusPath, "r");
  9871. if (fp1)
  9872. {
  9873. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9874. // file exists
  9875. fclose(fp1);
  9876. }
  9877. else
  9878. {
  9879. // file doesn't exist
  9880. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9881. }
  9882. }
  9883. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9884. {
  9885. mtrace();
  9886. int result = FAIL;
  9887. time_t CurrentTime;
  9888. struct tm *tm;
  9889. pthread_t th_Status;
  9890. CurrentTime = time(NULL);
  9891. tm = localtime(&CurrentTime);
  9892. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9893. 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);
  9894. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9895. if(!interLock.isGetDiagnosticGoing)
  9896. {
  9897. interLock.isGetDiagnosticGoing = 1;
  9898. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9899. sleep(1);
  9900. }
  9901. else
  9902. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9903. return result;
  9904. }
  9905. void* GetDiagnosticsProcess(void* data)
  9906. {
  9907. pthread_detach(pthread_self());
  9908. mtrace();
  9909. int retriesInt=0, retryIntervalInt=0;
  9910. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9911. 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};
  9912. int port=0;
  9913. int isSuccess = FALSE;
  9914. char ftpbuf[200]={0};
  9915. char cmdBuf[2048];
  9916. struct tm *tmNow;
  9917. time_t CurrentTime;
  9918. struct tm tmStart;
  9919. struct tm tmStop;
  9920. CurrentTime = time(NULL);
  9921. tmNow=localtime(&CurrentTime);
  9922. uint16_t targetYear, targetMonth;
  9923. json_object *GetDiagnostics;
  9924. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9925. GetDiagnostics = json_tokener_parse(data);
  9926. if(!is_error(GetDiagnostics))
  9927. {
  9928. // Required data
  9929. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9930. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9931. // Optional data
  9932. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9933. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9934. else
  9935. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9936. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9937. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9938. else
  9939. retryIntervalInt = 30;
  9940. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9941. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9942. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9943. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9944. }
  9945. json_object_put(GetDiagnostics);
  9946. // Pack log to compress file
  9947. 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) &&
  9948. (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))
  9949. {
  9950. // Pack system log
  9951. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9952. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9953. targetYear = tmStart.tm_year;
  9954. targetMonth = tmStart.tm_mon;
  9955. do
  9956. {
  9957. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9958. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9959. if(targetMonth+1>=13)
  9960. {
  9961. targetYear += 1;
  9962. targetMonth = 1;
  9963. }
  9964. else
  9965. {
  9966. targetMonth += 1;
  9967. }
  9968. }while((targetYear < (tmNow->tm_year+1900)) ||
  9969. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9970. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9971. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9972. system(cmdBuf);
  9973. // Pack charging & event log
  9974. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9975. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9976. targetYear = tmStart.tm_year;
  9977. targetMonth = tmStart.tm_mon;
  9978. do
  9979. {
  9980. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9981. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9982. if(targetMonth+1>=13)
  9983. {
  9984. targetYear += 1;
  9985. targetMonth = 1;
  9986. }
  9987. else
  9988. {
  9989. targetMonth += 1;
  9990. }
  9991. }while((targetYear < (tmNow->tm_year+1900)) ||
  9992. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9993. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9994. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9995. system(cmdBuf);
  9996. // Combine log file
  9997. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9998. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9999. }
  10000. else
  10001. {
  10002. system("exec /root/logPackTools 'log' 6");
  10003. }
  10004. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10005. system(cmdBuf);
  10006. checkUploadLog();
  10007. //****************location*******************/
  10008. if(strcmp(locationstr,"")==0)
  10009. {
  10010. DEBUG_INFO("location is <Empty>!\n");
  10011. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10012. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10013. goto end;
  10014. }
  10015. memset(protocol, 0, ARRAY_SIZE(protocol));
  10016. memset(user, 0, ARRAY_SIZE(user) );
  10017. memset(password, 0, ARRAY_SIZE(password));
  10018. memset(host, 0, ARRAY_SIZE(host));
  10019. memset(path, 0, ARRAY_SIZE(path));
  10020. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10021. memset(host1, 0, ARRAY_SIZE(host1));
  10022. memset(path1, 0, ARRAY_SIZE(path1));
  10023. /*location: ftp://user:password@host:port/path*/
  10024. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10025. if((access(fnamePlusPath,F_OK))!=-1)
  10026. {
  10027. DEBUG_INFO("fnamePlusPath exist.\n");
  10028. }
  10029. else
  10030. {
  10031. DEBUG_INFO("fnamePlusPath not exist!\n");
  10032. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10033. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10034. goto end;
  10035. }
  10036. if(strchr(locationstr,'@')==NULL)
  10037. {
  10038. sscanf(locationstr,
  10039. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10040. protocol, host, &port, path);
  10041. strcpy(user,"anonymous");
  10042. strcpy(password,"");
  10043. }
  10044. else
  10045. {
  10046. //DEBUG_INFO("pch=%s\n", pch);
  10047. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10048. protocol, user, password, host, &port, path);
  10049. }
  10050. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10051. {
  10052. DEBUG_INFO("protocol is not ftp/http ! \n");
  10053. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10054. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10055. goto end;
  10056. }
  10057. if(strncmp(locationstr,"http", 4) == 0)
  10058. {
  10059. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10060. sprintf(ftppath,"/%s", path);
  10061. do
  10062. {
  10063. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10064. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10065. sleep(3);
  10066. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10067. if(!isSuccess)
  10068. {
  10069. DEBUG_INFO("Diagnostics fail.\n");
  10070. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10071. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10072. sleep(retryIntervalInt);
  10073. }
  10074. else
  10075. {
  10076. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10077. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10078. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10079. }
  10080. retriesInt--;
  10081. }while((isSuccess == 0)&&(retriesInt >= 0));
  10082. }
  10083. else
  10084. {
  10085. sscanf(host,"%[^/]%s",host1, path1);
  10086. if(strlen(path) > 0)
  10087. sprintf(ftppath,"/%s", path);
  10088. else
  10089. sprintf(ftppath,"/%s", path1);
  10090. int ftppathlen=strlen(ftppath);
  10091. int i=1;
  10092. char filenametemp[50];
  10093. while(i < ftppathlen)
  10094. {
  10095. int len=ftppathlen-i;
  10096. if(ftppath[len]== 47) // '/' ascll code: 47
  10097. {
  10098. DEBUG_INFO("find '/' all right\n");
  10099. break;
  10100. }
  10101. i=i+1;
  10102. }
  10103. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10104. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10105. filenametemp[i+1] = 0;
  10106. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10107. if(port == 0)
  10108. port = 21;
  10109. do
  10110. {
  10111. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10112. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10113. sleep(3);
  10114. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10115. if(!isSuccess)
  10116. {
  10117. DEBUG_INFO("Diagnostics fail.\n");
  10118. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10119. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10120. sleep(retryIntervalInt);
  10121. }
  10122. else
  10123. {
  10124. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10125. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10126. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10127. }
  10128. retriesInt--;
  10129. }while((!isSuccess)&&(retriesInt >= 0));
  10130. }
  10131. end:
  10132. system("rm -f /mnt/*");
  10133. sleep(5);
  10134. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10135. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10136. interLock.isGetDiagnosticGoing = 0;
  10137. pthread_exit(NULL);
  10138. }
  10139. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10140. {
  10141. mtrace();
  10142. int result = FAIL;
  10143. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10144. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10145. {
  10146. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10147. locallistVersion = -1;
  10148. }
  10149. else
  10150. {
  10151. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10152. locallistVersion = 0;
  10153. OCPP_getListVerion();
  10154. }
  10155. //from db.OCPP_getListVerion
  10156. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10157. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10158. sendGetLocalListVersionConfirmation(uuid,"");
  10159. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10160. return result;
  10161. }
  10162. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10163. {
  10164. mtrace();
  10165. int result = FAIL;
  10166. int connectorIdInt=-1;
  10167. int tempIndex = 0;
  10168. int connectorIdIsNULL, chargingProfileIsNULL;
  10169. char comfirmstr[20]={0};
  10170. char cmdBuf[512];
  10171. json_object *RemoteStartTransaction;
  10172. FILE *fp;
  10173. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10174. if(server_pending == TRUE)
  10175. {
  10176. return 0;
  10177. }
  10178. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10179. RemoteStartTransaction = json_tokener_parse(payload);
  10180. if(!is_error(RemoteStartTransaction))
  10181. {
  10182. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10183. {
  10184. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10185. }
  10186. else
  10187. {
  10188. connectorIdIsNULL = TRUE;
  10189. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10190. {
  10191. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10192. {
  10193. connectorIdIsNULL = FALSE;
  10194. connectorIdInt = (gun_index+1);
  10195. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10196. break;
  10197. }
  10198. }
  10199. }
  10200. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10201. {
  10202. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10203. // Required data
  10204. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10205. // Optional data
  10206. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10207. {
  10208. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10209. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10210. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10211. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10212. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10213. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10214. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10215. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10216. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10217. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10218. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10219. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10220. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10221. {
  10222. 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")));
  10223. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10224. 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"));
  10225. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10226. 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"));
  10227. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10228. 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")));
  10229. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10230. {
  10231. 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++)
  10232. {
  10233. 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"));
  10234. 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"));
  10235. 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)
  10236. 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"));
  10237. }
  10238. }
  10239. }
  10240. }
  10241. else
  10242. {
  10243. chargingProfileIsNULL = TRUE;
  10244. }
  10245. }
  10246. }
  10247. else
  10248. {
  10249. connectorIdIsNULL = TRUE;
  10250. }
  10251. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10252. {
  10253. DEBUG_WARN("Connector id is NULL\n.");
  10254. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10255. goto end;
  10256. }
  10257. /*
  10258. enum _SYSTEM_STATUS
  10259. {
  10260. S_BOOTING = 0,
  10261. S_IDLE, = 1
  10262. S_AUTHORIZING, = 2
  10263. S_REASSIGN_CHECK, = 3
  10264. S_REASSIGN, = 4
  10265. S_PRECHARGE, = 5
  10266. S_PREPARING_FOR_EV, = 6
  10267. S_PREPARING_FOR_EVSE, = 7
  10268. S_CHARGING, = 8
  10269. S_TERMINATING, = 9
  10270. S_COMPLETE, = 10
  10271. S_ALARM, = 11
  10272. S_FAULT = 12
  10273. }
  10274. */
  10275. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10276. {
  10277. //check Transaction active
  10278. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10279. {
  10280. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10281. {
  10282. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10283. }
  10284. else
  10285. {
  10286. tempIndex = connectorIdInt -1;
  10287. }
  10288. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10289. {
  10290. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10291. {
  10292. 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))
  10293. {
  10294. //Reserved
  10295. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10296. }
  10297. 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))
  10298. {
  10299. //Reserved
  10300. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10301. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10302. goto end;
  10303. }
  10304. else
  10305. {
  10306. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10307. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10308. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10309. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10310. {
  10311. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10312. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10313. goto end;
  10314. }
  10315. }//END FOR ELSE
  10316. }
  10317. }// END FOR CHAdeMO_QUANTITY
  10318. }
  10319. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10320. {
  10321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10322. {
  10323. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10324. }
  10325. else
  10326. {
  10327. tempIndex = connectorIdInt -1;
  10328. }
  10329. for (int index = 0; index < CCS_QUANTITY; index++)
  10330. {
  10331. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10332. {
  10333. 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))
  10334. {
  10335. //Reserved
  10336. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10337. }
  10338. 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))
  10339. {
  10340. //Reserved
  10341. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10342. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10343. goto end;
  10344. }
  10345. else
  10346. {
  10347. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10348. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10349. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10350. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10351. {
  10352. DEBUG_WARN("CCS connector not allow start\n.");
  10353. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10354. goto end;
  10355. }
  10356. }// END FOR ELSE
  10357. }
  10358. }// END FOR CCS_QUANTITY
  10359. }
  10360. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10361. {
  10362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10363. {
  10364. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10365. }
  10366. else
  10367. {
  10368. tempIndex = connectorIdInt -1;
  10369. }
  10370. for (int index = 0; index < GB_QUANTITY; index++)
  10371. {
  10372. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10373. {
  10374. 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))
  10375. {
  10376. //Reserved
  10377. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10378. }
  10379. 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))
  10380. {
  10381. //Reserved
  10382. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10383. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10384. goto end;
  10385. }
  10386. else
  10387. {
  10388. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10389. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10390. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10391. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10392. {
  10393. DEBUG_WARN("GB connector not allow start\n.");
  10394. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10395. goto end;
  10396. }
  10397. }// END FOR ELSE
  10398. }
  10399. } // END FOR GB_QUANTITY
  10400. }
  10401. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10402. {
  10403. tempIndex = connectorIdInt -1;
  10404. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10405. {
  10406. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10407. {
  10408. 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))
  10409. {
  10410. //Reserved
  10411. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10412. }
  10413. 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))
  10414. {
  10415. //Reserved
  10416. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10417. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10418. goto end;
  10419. }
  10420. else
  10421. {
  10422. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10423. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10424. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10425. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10426. {
  10427. DEBUG_WARN("GB connector not allow start\n.");
  10428. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10429. goto end;
  10430. }
  10431. }// END FOR ELSE
  10432. }
  10433. } // END FOR GB_QUANTITY
  10434. }
  10435. else
  10436. {
  10437. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10438. {
  10439. tempIndex = 2;
  10440. }
  10441. else
  10442. {
  10443. tempIndex = connectorIdInt -1;
  10444. }
  10445. for (int index = 0; index < AC_QUANTITY; index++)
  10446. {
  10447. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10448. {
  10449. 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))
  10450. {
  10451. //Reserved
  10452. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10453. }
  10454. 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))
  10455. {
  10456. //Reserved
  10457. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10458. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10459. goto end;
  10460. }
  10461. else
  10462. {
  10463. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10464. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10465. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10466. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10467. {
  10468. DEBUG_WARN("AC connector not allow start\n.");
  10469. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10470. goto end;
  10471. }
  10472. }//END FOR ELSE
  10473. }
  10474. }// END FOR AC_QUANTITY
  10475. }
  10476. if(chargingProfileIsNULL == FALSE)
  10477. {
  10478. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10479. {
  10480. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10481. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10482. //memset idTag
  10483. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10484. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10485. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10486. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10487. // Save profile to file
  10488. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10489. system(cmdBuf);
  10490. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10491. fp = fopen(cmdBuf, "w");
  10492. 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));
  10493. fclose(fp);
  10494. }
  10495. else
  10496. {
  10497. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10498. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10499. }
  10500. }
  10501. else
  10502. {
  10503. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10504. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10505. //memset idTag
  10506. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10507. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10508. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10510. }
  10511. }
  10512. else
  10513. {
  10514. DEBUG_WARN("Connector id over\n.");
  10515. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10516. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10517. }
  10518. end:
  10519. json_object_put(RemoteStartTransaction);
  10520. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10521. {
  10522. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10523. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10524. }
  10525. //OCPP send RemoteStartConfirmation by first.
  10526. sendRemoteStartConfirmation(uuid, comfirmstr);
  10527. return result;
  10528. }
  10529. int handleRemoteStartRequest(char *uuid, char *payload)
  10530. {
  10531. mtrace();
  10532. int result = PASS;
  10533. int connectorIdInt=-1;
  10534. int tempIndex = 0;
  10535. char comfirmstr[20]={0};
  10536. char cmdBuf[512];
  10537. json_object *RemoteStartTransaction;
  10538. FILE *fp;
  10539. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10540. if(server_pending == TRUE)
  10541. {
  10542. result = FAIL;
  10543. }
  10544. RemoteStartTransaction = json_tokener_parse(payload);
  10545. if(!is_error(RemoteStartTransaction))
  10546. {
  10547. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10548. {
  10549. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10550. }
  10551. else
  10552. {
  10553. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10554. {
  10555. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10556. {
  10557. connectorIdInt = (gun_index+1);
  10558. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10559. break;
  10560. }
  10561. }
  10562. }
  10563. if(connectorIdInt == 0)
  10564. {
  10565. DEBUG_WARN("Connector id shall not equal 0.\n");
  10566. result = FAIL;
  10567. }
  10568. else if(connectorIdInt == -1)
  10569. {
  10570. DEBUG_INFO("Connector id does not specific.\n");
  10571. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10572. {
  10573. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10574. // Required data
  10575. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10576. // Optional data
  10577. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10578. {
  10579. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10580. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10581. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10582. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10583. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10584. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10585. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10586. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10587. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10588. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10589. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10590. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10591. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10592. {
  10593. 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")));
  10594. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10595. 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"));
  10596. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10597. 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"));
  10598. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10599. 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")));
  10600. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10601. {
  10602. 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++)
  10603. {
  10604. 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"));
  10605. 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"));
  10606. 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)
  10607. 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"));
  10608. }
  10609. }
  10610. }
  10611. }
  10612. else
  10613. {
  10614. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10615. }
  10616. }
  10617. }
  10618. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10619. {
  10620. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10621. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10622. // Required data
  10623. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10624. // Optional data
  10625. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10626. {
  10627. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10628. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10629. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10630. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10631. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10632. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10633. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10634. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10635. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10636. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10637. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10638. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10639. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10640. {
  10641. 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")));
  10642. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10643. 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"));
  10644. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10645. 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"));
  10646. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10647. 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")));
  10648. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10649. {
  10650. 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++)
  10651. {
  10652. 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"));
  10653. 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"));
  10654. 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)
  10655. 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"));
  10656. }
  10657. }
  10658. }
  10659. }
  10660. else
  10661. {
  10662. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10663. }
  10664. }
  10665. else
  10666. {
  10667. DEBUG_WARN("Connector id is over maximun value.\n");
  10668. result = FAIL;
  10669. }
  10670. }
  10671. if(result == PASS)
  10672. {
  10673. if(connectorIdInt > 0)
  10674. {
  10675. //check Transaction active
  10676. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10677. {
  10678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10679. {
  10680. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10681. }
  10682. else
  10683. {
  10684. tempIndex = connectorIdInt -1;
  10685. }
  10686. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10687. {
  10688. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10689. {
  10690. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10691. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10692. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10693. {
  10694. //Reserved
  10695. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10696. }
  10697. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10698. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10699. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10700. {
  10701. //Reserved
  10702. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10703. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10704. goto end;
  10705. }
  10706. else
  10707. {
  10708. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10709. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10710. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10711. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10712. {
  10713. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10714. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10715. goto end;
  10716. }
  10717. }//END FOR ELSE
  10718. }
  10719. }// END FOR CHAdeMO_QUANTITY
  10720. }
  10721. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10722. {
  10723. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10724. {
  10725. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10726. }
  10727. else
  10728. {
  10729. tempIndex = connectorIdInt -1;
  10730. }
  10731. for (int index = 0; index < CCS_QUANTITY; index++)
  10732. {
  10733. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10734. {
  10735. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10736. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10737. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10738. {
  10739. //Reserved
  10740. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10741. }
  10742. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10743. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10744. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10745. {
  10746. //Reserved
  10747. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10748. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10749. goto end;
  10750. }
  10751. else
  10752. {
  10753. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10754. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10755. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10756. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10757. {
  10758. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10759. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10760. goto end;
  10761. }
  10762. }// END FOR ELSE
  10763. }
  10764. }// END FOR CCS_QUANTITY
  10765. }
  10766. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10767. {
  10768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10769. {
  10770. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10771. }
  10772. else
  10773. {
  10774. tempIndex = connectorIdInt -1;
  10775. }
  10776. for (int index = 0; index < GB_QUANTITY; index++)
  10777. {
  10778. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10779. {
  10780. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10781. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10782. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10783. {
  10784. //Reserved
  10785. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10786. }
  10787. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10788. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10789. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10790. {
  10791. //Reserved
  10792. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10793. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10794. goto end;
  10795. }
  10796. else
  10797. {
  10798. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10799. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10800. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10801. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10802. {
  10803. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10804. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10805. goto end;
  10806. }
  10807. }// END FOR ELSE
  10808. }
  10809. } // END FOR GB_QUANTITY
  10810. }
  10811. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10812. {
  10813. tempIndex = connectorIdInt -1;
  10814. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10815. {
  10816. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10817. {
  10818. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10819. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10820. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10821. {
  10822. //Reserved
  10823. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10824. }
  10825. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10826. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10827. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10828. {
  10829. //Reserved
  10830. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10831. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10832. goto end;
  10833. }
  10834. else
  10835. {
  10836. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10837. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10838. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10839. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10840. {
  10841. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10842. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10843. goto end;
  10844. }
  10845. }// END FOR ELSE
  10846. }
  10847. } // END FOR GB_QUANTITY
  10848. }
  10849. else
  10850. {
  10851. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10852. {
  10853. tempIndex = 2;
  10854. }
  10855. else
  10856. {
  10857. tempIndex = connectorIdInt -1;
  10858. }
  10859. for (int index = 0; index < AC_QUANTITY; index++)
  10860. {
  10861. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10862. {
  10863. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10864. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10865. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10866. {
  10867. //Reserved
  10868. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10869. }
  10870. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10871. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10872. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10873. {
  10874. //Reserved
  10875. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10876. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10877. goto end;
  10878. }
  10879. else
  10880. {
  10881. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10882. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10883. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10884. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10885. {
  10886. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10887. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10888. goto end;
  10889. }
  10890. }//END FOR ELSE
  10891. }
  10892. }// END FOR AC_QUANTITY
  10893. }
  10894. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10895. {
  10896. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10897. {
  10898. // Save profile to file
  10899. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10900. system(cmdBuf);
  10901. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10902. fp = fopen(cmdBuf, "w");
  10903. 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));
  10904. fclose(fp);
  10905. }
  10906. else
  10907. {
  10908. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10909. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10910. goto end;
  10911. }
  10912. }
  10913. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10914. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10915. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10916. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10917. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10918. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10919. }
  10920. else
  10921. {
  10922. uint8_t isHasIdleConnector = FALSE;
  10923. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10924. {
  10925. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10926. {
  10927. isHasIdleConnector = TRUE;
  10928. break;
  10929. }
  10930. }
  10931. if(isHasIdleConnector == TRUE)
  10932. {
  10933. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10934. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10935. {
  10936. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10937. {
  10938. // Save profile to file
  10939. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10940. system(cmdBuf);
  10941. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10942. fp = fopen(cmdBuf, "w");
  10943. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10944. fclose(fp);
  10945. refreshStartTimer(&clientTime.RemoteStartWait);
  10946. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10947. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10948. }
  10949. else
  10950. {
  10951. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10952. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10953. }
  10954. }
  10955. else
  10956. {
  10957. refreshStartTimer(&clientTime.RemoteStartWait);
  10958. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10959. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10960. }
  10961. }
  10962. else
  10963. {
  10964. DEBUG_INFO("There is not any connector is idle.\n");
  10965. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10966. }
  10967. }
  10968. }
  10969. else
  10970. {
  10971. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10972. }
  10973. end:
  10974. json_object_put(RemoteStartTransaction);
  10975. sendRemoteStartConfirmation(uuid, comfirmstr);
  10976. return result;
  10977. }
  10978. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10979. {
  10980. mtrace();
  10981. int result = FAIL;
  10982. int match = FALSE;
  10983. int GunNO = 0;
  10984. int tempIndex = 0;
  10985. int transactionIdInt=0;
  10986. int transactionIdIsNULL= TRUE;
  10987. char comfirmstr[20];
  10988. json_object *RemoteStopTransaction;
  10989. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10990. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10991. if(server_pending == TRUE)
  10992. {
  10993. return 0;
  10994. }
  10995. RemoteStopTransaction = json_tokener_parse(payload);
  10996. if(!is_error(RemoteStopTransaction))
  10997. {
  10998. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10999. {
  11000. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11001. transactionIdIsNULL = FALSE;
  11002. }
  11003. }
  11004. json_object_put(RemoteStopTransaction);
  11005. if(transactionIdIsNULL == FALSE)
  11006. {
  11007. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11008. {
  11009. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11010. {
  11011. //check Transaction active
  11012. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11013. {
  11014. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11015. {
  11016. tempIndex = ((gun_index==2) ? 1: 0);
  11017. }
  11018. else
  11019. {
  11020. tempIndex = gun_index;
  11021. }
  11022. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11023. {
  11024. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11025. {
  11026. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11027. {
  11028. match = TRUE;
  11029. GunNO = gun_index;
  11030. }
  11031. }
  11032. }// END FOR CHAdeMO_QUANTITY
  11033. }
  11034. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11035. {
  11036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11037. {
  11038. tempIndex = ((gun_index==2) ? 1: 0);
  11039. }
  11040. else
  11041. {
  11042. tempIndex = gun_index;
  11043. }
  11044. for (int index = 0; index < CCS_QUANTITY; index++)
  11045. {
  11046. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11047. {
  11048. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11049. {
  11050. match = TRUE;
  11051. GunNO = gun_index;
  11052. }
  11053. }
  11054. }// END FOR CCS_QUANTITY
  11055. }
  11056. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11057. {
  11058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11059. {
  11060. tempIndex = ((gun_index==2) ? 1: 0);
  11061. }
  11062. else
  11063. {
  11064. tempIndex = gun_index;
  11065. }
  11066. for (int index = 0; index < GB_QUANTITY; index++)
  11067. {
  11068. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11069. {
  11070. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11071. {
  11072. match = TRUE;
  11073. GunNO = gun_index;
  11074. }
  11075. }
  11076. }// END FOR GB_QUANTITY
  11077. }
  11078. else if(gunType[gun_index] == GUN_TYPE_DO)
  11079. {
  11080. tempIndex = gun_index;
  11081. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11082. {
  11083. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11084. {
  11085. 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
  11086. {
  11087. match = TRUE;
  11088. GunNO = gun_index;
  11089. }
  11090. }
  11091. }// END FOR GB_QUANTITY
  11092. }
  11093. else
  11094. {
  11095. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11096. {
  11097. tempIndex = 2;
  11098. }
  11099. else
  11100. {
  11101. tempIndex = gun_index;
  11102. }
  11103. for (int index = 0; index < AC_QUANTITY; index++)
  11104. {
  11105. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11106. {
  11107. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11108. {
  11109. match = TRUE;
  11110. GunNO = gun_index;
  11111. }
  11112. }
  11113. }// END FOR CHAdeMO_QUANTITY
  11114. } // END FOR AC ELSE
  11115. }// CHECK IF ResponseTransactionId == transactionIdInt
  11116. }//END FOR
  11117. if( match == TRUE)
  11118. {
  11119. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11120. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11121. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11122. }
  11123. else
  11124. {
  11125. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11126. }
  11127. }
  11128. else
  11129. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11130. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11131. return result;
  11132. }
  11133. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11134. {
  11135. mtrace();
  11136. int result = FAIL;
  11137. int connectorIdInt=0, reservationIdInt=0;
  11138. int tempIndex = 0;
  11139. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11140. char comfirmstr[20]={0};
  11141. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11142. int c = 0;
  11143. char *loc;
  11144. //char *ptr;
  11145. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11146. strcpy(sstrtemp, stringtrimspace(payload));
  11147. //***(1)connectorId ****/
  11148. c=0;
  11149. loc = strstr(sstrtemp, "connectorId");
  11150. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11151. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11152. {
  11153. sstr[c] = loc[strlen("connectorId")+2+c];
  11154. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11155. c++;
  11156. }
  11157. sstr[c] = '\0';
  11158. connectorIdInt = atoi(sstr);
  11159. //***(2)expiryDate ****/
  11160. loc = strstr(sstrtemp, "expiryDate");
  11161. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11162. c = 0;
  11163. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11164. {
  11165. sstr[c] = loc[3+strlen("expiryDate")+c];
  11166. c++;
  11167. }
  11168. sstr[c] = '\0';
  11169. strcpy(expiryDatestr, sstr);
  11170. //***(3)idTag ****/
  11171. loc = strstr(sstrtemp, "idTag");
  11172. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11173. c = 0;
  11174. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11175. {
  11176. sstr[c] = loc[3+strlen("idTag")+c];
  11177. c++;
  11178. }
  11179. sstr[c] = '\0';
  11180. strcpy(idTagstr, sstr);
  11181. //***(4)parentIdTag ****/
  11182. loc = strstr(sstrtemp, "parentIdTag");
  11183. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11184. c = 0;
  11185. if(loc == NULL)
  11186. {
  11187. strcpy(parentIdTagstr, "");
  11188. }
  11189. else
  11190. {
  11191. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11192. {
  11193. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11194. c++;
  11195. }
  11196. sstr[c] = '\0';
  11197. strcpy(parentIdTagstr, sstr);
  11198. }
  11199. //***(5)reservationId ****/
  11200. c=0;
  11201. loc = strstr(sstrtemp, "reservationId");
  11202. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11203. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11204. {
  11205. sstr[c] = loc[strlen("reservationId")+2+c];
  11206. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11207. c++;
  11208. }
  11209. sstr[c] = '\0';
  11210. reservationIdInt = atoi(sstr);
  11211. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11212. /*
  11213. enum SYSTEM_STATUS
  11214. {
  11215. SYS_MODE_BOOTING = 0,
  11216. SYS_MODE_IDLE = 1,
  11217. SYS_MODE_AUTHORIZING = 2,
  11218. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11219. SYS_MODE_REASSIGN = 4,
  11220. SYS_MODE_PREPARING = 5,
  11221. SYS_MODE_PREPARE_FOR_EV = 6,
  11222. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11223. SYS_MODE_CHARGING = 8,
  11224. SYS_MODE_TERMINATING = 9,
  11225. SYS_MODE_COMPLETE = 10,
  11226. SYS_MODE_ALARM = 11,
  11227. SYS_MODE_FAULT = 12,
  11228. SYS_MODE_RESERVATION = 13,
  11229. SYS_MODE_BOOKING = 14,
  11230. SYS_MODE_MAINTAIN = 15,
  11231. SYS_MODE_DEBUG = 16,
  11232. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11233. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11234. SYS_MODE_UPDATE = 19
  11235. };
  11236. */
  11237. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11238. {
  11239. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11240. goto end;
  11241. }
  11242. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11243. {
  11244. //check Transaction active
  11245. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11246. {
  11247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11248. {
  11249. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11250. }
  11251. else
  11252. {
  11253. tempIndex = connectorIdInt -1;
  11254. }
  11255. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11256. {
  11257. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11258. {
  11259. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11260. {
  11261. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11262. {
  11263. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11264. {
  11265. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11266. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11267. }
  11268. 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'))
  11269. {
  11270. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11271. }
  11272. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11273. {
  11274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11275. }
  11276. else
  11277. {
  11278. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11279. }
  11280. }
  11281. 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
  11282. {
  11283. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11284. }
  11285. }
  11286. else
  11287. {
  11288. //replace reservation
  11289. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11290. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11291. }
  11292. }
  11293. } // END FOR CHAdeMO_QUANTITY
  11294. }
  11295. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11296. {
  11297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11298. {
  11299. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11300. }
  11301. else
  11302. {
  11303. tempIndex = connectorIdInt -1;
  11304. }
  11305. for (int index = 0; index < CCS_QUANTITY; index++)
  11306. {
  11307. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11308. {
  11309. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11310. {
  11311. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11312. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11313. {
  11314. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11315. {
  11316. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11317. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11318. }
  11319. 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'))
  11320. {
  11321. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11322. }
  11323. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11324. {
  11325. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11326. }
  11327. else
  11328. {
  11329. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11330. }
  11331. }
  11332. 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
  11333. {
  11334. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11335. }
  11336. }
  11337. else
  11338. {
  11339. //replace reservation
  11340. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11341. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11342. }
  11343. }
  11344. } // END FOR CCS_QUANTITY
  11345. }
  11346. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11347. {
  11348. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11349. {
  11350. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11351. }
  11352. else
  11353. {
  11354. tempIndex = connectorIdInt -1;
  11355. }
  11356. for (int index = 0; index < GB_QUANTITY; index++)
  11357. {
  11358. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11359. {
  11360. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11361. {
  11362. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11363. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11364. {
  11365. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11366. {
  11367. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11368. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11369. }
  11370. 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'))
  11371. {
  11372. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11373. }
  11374. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11375. {
  11376. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11377. }
  11378. else
  11379. {
  11380. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11381. }
  11382. }
  11383. 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
  11384. {
  11385. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11386. }
  11387. }
  11388. else
  11389. {
  11390. //replace reservation
  11391. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11392. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11393. }
  11394. }
  11395. }// END FOR GB_QUANTITY
  11396. }
  11397. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11398. {
  11399. tempIndex = connectorIdInt -1;
  11400. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11401. {
  11402. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11403. {
  11404. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11405. {
  11406. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11407. 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
  11408. {
  11409. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11410. {
  11411. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11412. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11413. }
  11414. 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'))
  11415. {
  11416. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11417. }
  11418. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11419. {
  11420. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11421. }
  11422. else
  11423. {
  11424. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11425. }
  11426. }
  11427. 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
  11428. {
  11429. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11430. }
  11431. }
  11432. else
  11433. {
  11434. //replace reservation
  11435. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11436. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11437. }
  11438. }
  11439. }// END FOR GB_QUANTITY
  11440. }
  11441. else
  11442. {
  11443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11444. {
  11445. tempIndex = 2;
  11446. }
  11447. else
  11448. {
  11449. tempIndex = (connectorIdInt -1);
  11450. }
  11451. for (int index = 0; index < AC_QUANTITY; index++)
  11452. {
  11453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11454. {
  11455. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11456. {
  11457. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11458. {
  11459. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11460. {
  11461. 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))
  11462. {
  11463. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11464. }
  11465. else
  11466. {
  11467. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11468. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11469. }
  11470. }
  11471. 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'))
  11472. {
  11473. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11474. }
  11475. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11476. {
  11477. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11478. }
  11479. else
  11480. {
  11481. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11482. }
  11483. }
  11484. 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
  11485. {
  11486. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11487. }
  11488. }
  11489. else
  11490. {
  11491. //replace reservation
  11492. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11493. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11494. }
  11495. }
  11496. } // END FOR AC_QUANTITY
  11497. }
  11498. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11499. }
  11500. else if(connectorIdInt == 0)
  11501. {
  11502. //check Transaction active
  11503. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11504. {
  11505. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11506. {
  11507. 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'))
  11508. {
  11509. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11510. goto end;
  11511. }
  11512. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11513. {
  11514. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11515. goto end;
  11516. }
  11517. 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
  11518. {
  11519. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11520. goto end;
  11521. }
  11522. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11523. {
  11524. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11525. goto end;
  11526. }
  11527. }
  11528. }// END FOR CHAdeMO_QUANTITY
  11529. for (int index = 0; index < CCS_QUANTITY; index++)
  11530. {
  11531. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11532. {
  11533. 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'))
  11534. {
  11535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11536. goto end;
  11537. }
  11538. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11539. {
  11540. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11541. goto end;
  11542. }
  11543. 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
  11544. {
  11545. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11546. goto end;
  11547. }
  11548. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11549. {
  11550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11551. goto end;
  11552. }
  11553. }
  11554. } // END FOR CCS_QUANTITY
  11555. for (int index = 0; index < GB_QUANTITY; index++)
  11556. {
  11557. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11558. {
  11559. 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'))
  11560. {
  11561. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11562. goto end;
  11563. }
  11564. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11565. {
  11566. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11567. goto end;
  11568. }
  11569. 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
  11570. {
  11571. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11572. goto end;
  11573. }
  11574. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11575. {
  11576. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11577. goto end;
  11578. }
  11579. }
  11580. } // END FOR GB_QUANTITY
  11581. for (int index = 0; index < AC_QUANTITY; index++)
  11582. {
  11583. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11584. {
  11585. 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'))
  11586. {
  11587. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11588. goto end;
  11589. }
  11590. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11591. {
  11592. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11593. goto end;
  11594. }
  11595. 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
  11596. {
  11597. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11598. goto end;
  11599. }
  11600. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11601. {
  11602. 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))
  11603. {
  11604. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11605. goto end;
  11606. }
  11607. }
  11608. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11609. {
  11610. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11611. goto end;
  11612. }
  11613. }
  11614. }// END FOR AC_QUANTITY
  11615. //The connectorId is 0
  11616. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11617. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11618. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11619. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11620. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11621. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11622. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11623. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11624. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11625. result = TRUE;
  11626. return result;
  11627. }
  11628. else
  11629. {
  11630. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11631. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11632. }
  11633. if(strcmp(comfirmstr,"Accepted") == 0)
  11634. {
  11635. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11636. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11637. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11638. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11639. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11640. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11641. result = TRUE;
  11642. return result;
  11643. }
  11644. end:
  11645. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11646. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11647. return result;
  11648. }
  11649. int handleResetRequest(char *uuid, char *payload)
  11650. {
  11651. mtrace();
  11652. int result = FAIL;
  11653. char sstr[10]={0},sstrtemp[30]={ 0 };
  11654. char typestr[10]={0};
  11655. char comfirmstr[20]={0};
  11656. int c = 0;
  11657. char *loc;
  11658. DEBUG_INFO("handleResetRequest...\n");
  11659. strcpy(sstrtemp, stringtrimspace(payload));
  11660. loc = strstr(sstrtemp, "type");
  11661. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11662. c = 0;
  11663. while (loc[3+strlen("type")+c] != '\"')
  11664. {
  11665. sstr[c] = loc[3+strlen("type")+c];
  11666. c++;
  11667. }
  11668. sstr[c] = '\0';
  11669. strcpy(typestr,sstr);
  11670. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11671. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11672. {
  11673. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11674. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11675. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11676. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11677. }
  11678. else
  11679. {
  11680. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11681. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11682. result = PASS;
  11683. }
  11684. sendResetConfirmation(uuid, comfirmstr);
  11685. return result;
  11686. }
  11687. int handleSendLocalListRequest(char *uuid, char *payload)
  11688. {
  11689. mtrace();
  11690. int result = FAIL;
  11691. char comfirmstr[20];
  11692. int checkState_Faulted = FALSE;
  11693. json_object *SendLocalList;
  11694. DEBUG_INFO("handleSendLocalListRequest...\n");
  11695. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11696. {
  11697. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11698. goto end;
  11699. }
  11700. //check Charge Point state
  11701. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11702. {
  11703. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11704. {
  11705. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11706. }
  11707. }
  11708. for (int index = 0; index < CCS_QUANTITY; index++)
  11709. {
  11710. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11711. {
  11712. checkState_Faulted = TRUE; //OCPP Status
  11713. }
  11714. }
  11715. for (int index = 0; index < GB_QUANTITY; index++)
  11716. {
  11717. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11718. {
  11719. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11720. }
  11721. }
  11722. //check Charge Point state
  11723. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11724. {
  11725. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11726. {
  11727. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11728. }
  11729. }
  11730. //check Charge Point state
  11731. for (int index = 0; index < AC_QUANTITY; index++)
  11732. {
  11733. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11734. {
  11735. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11736. }
  11737. }
  11738. if(checkState_Faulted == TRUE)
  11739. {
  11740. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11741. goto end;
  11742. }
  11743. // Parsing payload
  11744. SendLocalList = json_tokener_parse(payload);
  11745. if(!is_error(SendLocalList))
  11746. {
  11747. // Required data
  11748. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11749. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11750. // Optional data
  11751. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11752. {
  11753. //Check UpdateType
  11754. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11755. {
  11756. //Local list full update
  11757. DEBUG_INFO("Local list full update.\n");
  11758. locallistVersion = 0;
  11759. OCPP_getListVerion();
  11760. /*if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11761. {
  11762. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11763. goto end;
  11764. }*/
  11765. OCPP_cleanLocalList();
  11766. }
  11767. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11768. {
  11769. //Local list different update
  11770. DEBUG_INFO("Local list different update.\n");
  11771. locallistVersion = 0;
  11772. OCPP_getListVerion();
  11773. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11774. {
  11775. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11776. goto end;
  11777. }
  11778. }
  11779. else
  11780. {
  11781. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11782. goto end;
  11783. }
  11784. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11785. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11786. {
  11787. 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")));
  11788. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11789. {
  11790. 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")));
  11791. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11792. 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")));
  11793. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11794. 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")));
  11795. }
  11796. // Add to db
  11797. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11798. {
  11799. //Local list full update
  11800. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11801. idx,
  11802. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11803. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11804. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11805. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11806. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11807. // update list
  11808. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11809. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11810. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11811. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11812. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11813. }
  11814. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11815. {
  11816. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11817. idx,
  11818. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11819. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11820. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11821. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11822. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11823. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11824. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11825. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11826. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11827. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11828. }
  11829. }
  11830. }
  11831. else
  11832. {
  11833. //Check UpdateType
  11834. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11835. {
  11836. //Local list full update
  11837. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11838. OCPP_cleanLocalList();
  11839. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11840. goto end;
  11841. }
  11842. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11843. {
  11844. //Local list different update
  11845. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11846. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11847. goto end;
  11848. }
  11849. }
  11850. result = PASS;
  11851. }
  11852. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11853. end:
  11854. json_object_put(SendLocalList);
  11855. sendSendLocalListConfirmation(uuid, comfirmstr);
  11856. return result;
  11857. }
  11858. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11859. {
  11860. mtrace();
  11861. int result = FAIL;
  11862. struct StructSetChargingProfile SetProfileReq = {0};
  11863. int tempchargingProfileIdInt;
  11864. int tempstackLevelInt;
  11865. int chargingSchedulePeriodCount = 0;
  11866. char comfirmstr[20]={0};
  11867. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11868. char rmFileCmd[128]={0};
  11869. int profileQuantity = 0;
  11870. int replaceableProfileCnt = 0;
  11871. json_object *SetChargingProfile;
  11872. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11873. SetChargingProfile = json_tokener_parse(payload);
  11874. if(!is_error(SetChargingProfile))
  11875. {
  11876. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11877. {
  11878. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11879. }
  11880. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11881. {
  11882. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11883. {
  11884. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11885. }
  11886. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11887. {
  11888. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11889. }
  11890. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11891. {
  11892. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11893. }
  11894. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11895. {
  11896. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11897. }
  11898. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11899. {
  11900. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11901. }
  11902. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11903. {
  11904. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11905. }
  11906. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11907. {
  11908. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11909. }
  11910. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11911. {
  11912. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11913. }
  11914. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11915. {
  11916. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11917. {
  11918. 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")));
  11919. }
  11920. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11921. {
  11922. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11923. }
  11924. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11925. {
  11926. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11927. }
  11928. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11929. {
  11930. 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")));
  11931. }
  11932. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11933. {
  11934. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11935. if(chargingSchedulePeriodCount <= 10)
  11936. {
  11937. 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++)
  11938. {
  11939. 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)
  11940. {
  11941. 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"));
  11942. }
  11943. 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)
  11944. {
  11945. 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"));
  11946. }
  11947. 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)
  11948. {
  11949. 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"));
  11950. }
  11951. }
  11952. }
  11953. }
  11954. }
  11955. }
  11956. }
  11957. // Profile periods quantity check
  11958. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11959. {
  11960. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11961. goto end;
  11962. }
  11963. // Check invalid limit
  11964. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  11965. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  11966. {
  11967. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11968. {
  11969. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11970. {
  11971. 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)))) ||
  11972. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11973. {
  11974. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11975. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11976. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11977. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11978. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11979. goto end;
  11980. }
  11981. }
  11982. }
  11983. else
  11984. {
  11985. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11986. {
  11987. 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) ||
  11988. (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)))
  11989. {
  11990. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11991. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11992. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11993. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11994. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11995. goto end;
  11996. }
  11997. }
  11998. }
  11999. }
  12000. // Profile purpose info check
  12001. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12002. {
  12003. FILE *fp;
  12004. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12005. if(SetProfileReq.ConnectorId != 0)
  12006. {
  12007. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12008. goto end;
  12009. }
  12010. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12011. if (!fp)
  12012. {
  12013. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12014. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12015. }
  12016. else
  12017. {
  12018. char *line = NULL;
  12019. size_t len = 0;
  12020. while(getline(&line, &len, fp) != -1)
  12021. {
  12022. json_object *obj = NULL;
  12023. obj = json_tokener_parse(line);
  12024. if(is_error(obj))
  12025. {
  12026. DEBUG_ERROR("Parse txProfile from file error.\n");
  12027. }
  12028. else
  12029. {
  12030. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12031. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12032. {
  12033. profileQuantity += 1;
  12034. }
  12035. else
  12036. replaceableProfileCnt += 1;
  12037. }
  12038. }
  12039. }
  12040. fclose(fp);
  12041. }
  12042. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12043. {
  12044. FILE *fp;
  12045. char filename[128]={0};
  12046. int tmpProfileQuantity;
  12047. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12048. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12049. {
  12050. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12051. goto end;
  12052. }
  12053. if(SetProfileReq.ConnectorId == 0)
  12054. {
  12055. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12056. {
  12057. tmpProfileQuantity = 0;
  12058. memset(filename, 0, ARRAY_SIZE(filename));
  12059. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12060. fp = fopen(filename, "r");
  12061. if (!fp)
  12062. {
  12063. DEBUG_INFO("%s does not create.\n", filename);
  12064. fp = fopen(filename, "w+");
  12065. }
  12066. else
  12067. {
  12068. char *line = NULL;
  12069. size_t len = 0;
  12070. while(getline(&line, &len, fp) != -1)
  12071. {
  12072. json_object *obj = NULL;
  12073. obj = json_tokener_parse(line);
  12074. if(is_error(obj))
  12075. {
  12076. DEBUG_ERROR("Parse txProfile from file error.\n");
  12077. }
  12078. else
  12079. {
  12080. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12081. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12082. {
  12083. tmpProfileQuantity += 1;
  12084. }
  12085. else
  12086. replaceableProfileCnt += 1;
  12087. }
  12088. }
  12089. }
  12090. fclose(fp);
  12091. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12092. }
  12093. }
  12094. else
  12095. {
  12096. memset(filename, 0, ARRAY_SIZE(filename));
  12097. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12098. fp = fopen(filename, "r");
  12099. if (!fp)
  12100. {
  12101. DEBUG_INFO("%s does not create.\n", filename);
  12102. fp = fopen(filename, "w+");
  12103. }
  12104. else
  12105. {
  12106. char *line = NULL;
  12107. size_t len = 0;
  12108. while(getline(&line, &len, fp) != -1)
  12109. {
  12110. json_object *obj = NULL;
  12111. obj = json_tokener_parse(line);
  12112. if(is_error(obj))
  12113. {
  12114. DEBUG_ERROR("Parse txProfile from file error.\n");
  12115. }
  12116. else
  12117. {
  12118. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12119. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12120. {
  12121. profileQuantity += 1;
  12122. }
  12123. else
  12124. replaceableProfileCnt += 1;
  12125. }
  12126. }
  12127. }
  12128. fclose(fp);
  12129. }
  12130. }
  12131. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12132. {
  12133. int isMatchTransactiodId= FALSE;
  12134. FILE *fp;
  12135. char filename[128]={0};
  12136. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12137. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12138. if(SetProfileReq.ConnectorId == 0)
  12139. {
  12140. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12141. goto end;
  12142. }
  12143. int tempIndex = 0;
  12144. //check Transaction active
  12145. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12146. {
  12147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12148. {
  12149. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12150. }
  12151. else
  12152. {
  12153. tempIndex = SetProfileReq.ConnectorId -1;
  12154. }
  12155. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12156. {
  12157. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12158. {
  12159. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12160. {
  12161. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12162. {
  12163. isMatchTransactiodId = TRUE;
  12164. break;
  12165. }
  12166. }
  12167. }
  12168. }
  12169. }
  12170. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12171. {
  12172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12173. {
  12174. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12175. }
  12176. else
  12177. {
  12178. tempIndex = SetProfileReq.ConnectorId -1;
  12179. }
  12180. for (int index = 0; index < CCS_QUANTITY; index++)
  12181. {
  12182. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12183. {
  12184. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12185. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12186. {
  12187. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12188. {
  12189. isMatchTransactiodId = TRUE;
  12190. break;
  12191. }
  12192. }
  12193. }
  12194. }
  12195. }
  12196. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12197. {
  12198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12199. {
  12200. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12201. }
  12202. else
  12203. {
  12204. tempIndex = SetProfileReq.ConnectorId -1;
  12205. }
  12206. for (int index = 0; index < GB_QUANTITY; index++)
  12207. {
  12208. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12209. {
  12210. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12211. {
  12212. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12213. {
  12214. isMatchTransactiodId = TRUE;
  12215. break;
  12216. }
  12217. }
  12218. }
  12219. }
  12220. }
  12221. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12222. {
  12223. tempIndex = SetProfileReq.ConnectorId -1;
  12224. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12225. {
  12226. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12227. {
  12228. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12229. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12230. {
  12231. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12232. {
  12233. isMatchTransactiodId = TRUE;
  12234. break;
  12235. }
  12236. }
  12237. }
  12238. }
  12239. }
  12240. else
  12241. {
  12242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12243. {
  12244. tempIndex = 2;
  12245. }
  12246. else
  12247. {
  12248. tempIndex = (SetProfileReq.ConnectorId -1);
  12249. }
  12250. for (int index = 0; index < AC_QUANTITY; index++)
  12251. {
  12252. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12253. {
  12254. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12255. {
  12256. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12257. {
  12258. isMatchTransactiodId = TRUE;
  12259. break;
  12260. }
  12261. }
  12262. }
  12263. }
  12264. }
  12265. //check Transaction active
  12266. if(isMatchTransactiodId == FALSE)
  12267. {
  12268. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12269. goto end;
  12270. }
  12271. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12272. {
  12273. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12274. goto end;
  12275. }
  12276. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12277. fp = fopen(filename, "r");
  12278. if (!fp)
  12279. {
  12280. DEBUG_INFO("%s does not create.\n", filename);
  12281. fp = fopen(filename, "w+");
  12282. }
  12283. else
  12284. {
  12285. char *line = NULL;
  12286. size_t len = 0;
  12287. while(getline(&line, &len, fp) != -1)
  12288. {
  12289. json_object *obj = NULL;
  12290. obj = json_tokener_parse(line);
  12291. if(is_error(obj))
  12292. {
  12293. DEBUG_ERROR("Parse txProfile from file error.\n");
  12294. }
  12295. else
  12296. {
  12297. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12298. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12299. {
  12300. profileQuantity += 1;
  12301. }
  12302. else
  12303. replaceableProfileCnt += 1;
  12304. }
  12305. }
  12306. }
  12307. fclose(fp);
  12308. }
  12309. // Check ChargeProfileMaxStackLevel
  12310. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12311. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12312. {
  12313. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12314. goto end;
  12315. }
  12316. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12317. {
  12318. FILE *fp;
  12319. char dataLine[4096]={0};
  12320. char fnametemp[128]={0};
  12321. int tmpProfileQuantity;
  12322. //Check ChargePointMaxProfile.json exit
  12323. profileQuantity = 0;
  12324. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12325. {
  12326. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12327. //Check Charging Profile Count
  12328. tmpProfileQuantity = 0;
  12329. while(fscanf(fp, "%s", dataLine) != EOF)
  12330. {
  12331. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12332. {
  12333. profileQuantity += 1;
  12334. tmpProfileQuantity += 1;
  12335. }
  12336. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12337. }
  12338. fclose(fp);
  12339. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12340. }
  12341. //Check TxDefaultProfile_%d.json
  12342. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12343. {
  12344. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12345. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12346. if((access(fnametemp,F_OK))!=-1)
  12347. {
  12348. fp = fopen(fnametemp, "r");
  12349. //Check Charging Profile Count
  12350. tmpProfileQuantity = 0;
  12351. while(fscanf(fp, "%s", dataLine) != EOF)
  12352. {
  12353. //DEBUG_INFO("word=%s\n",word);
  12354. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12355. {
  12356. profileQuantity += 1;
  12357. tmpProfileQuantity += 1;
  12358. }
  12359. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12360. }
  12361. fclose(fp);
  12362. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12363. }
  12364. }
  12365. //Check TxProfile_%d.json
  12366. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12367. {
  12368. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12369. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12370. if((access(fnametemp,F_OK))!=-1)
  12371. {
  12372. fp = fopen(fnametemp, "r");
  12373. //Check Charging Profile Count
  12374. tmpProfileQuantity = 0;
  12375. while(fscanf(fp, "%s", dataLine) != EOF)
  12376. {
  12377. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12378. {
  12379. profileQuantity += 1;
  12380. tmpProfileQuantity += 1;
  12381. }
  12382. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12383. }
  12384. fclose(fp);
  12385. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12386. }
  12387. }
  12388. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12389. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12390. // To check total Profile quantity
  12391. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12392. {
  12393. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12394. {
  12395. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12396. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12397. goto end;
  12398. }
  12399. }
  12400. else
  12401. {
  12402. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12403. {
  12404. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12405. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12406. goto end;
  12407. }
  12408. }
  12409. }
  12410. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12411. //**********************************Write to File********************************************************/
  12412. {
  12413. FILE *infile;
  12414. FILE *outfile;
  12415. char dataLine[4096]={0};
  12416. char filename[128]={0};
  12417. int chkChar=0;
  12418. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12419. {
  12420. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12421. {
  12422. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12423. }
  12424. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12425. {
  12426. if(SetProfileReq.ConnectorId==0)
  12427. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12428. else
  12429. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12430. }
  12431. else
  12432. {
  12433. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12434. }
  12435. infile = fopen (filename, "r");
  12436. outfile = fopen (tempfile, "w");
  12437. chkChar = fgetc(infile);
  12438. rewind(infile);
  12439. if(chkChar == EOF)
  12440. {
  12441. // Profile is empty
  12442. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12443. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12444. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12445. fclose(infile);
  12446. fclose(outfile);
  12447. sprintf(rmFileCmd,"rm -f %s",filename);
  12448. system(rmFileCmd);
  12449. rename(tempfile, filename);
  12450. }
  12451. else
  12452. {
  12453. // Profile is not empty
  12454. int ChargingProfileAdded = FALSE;
  12455. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12456. {
  12457. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12458. json_object *tmpChargingProfile;
  12459. tmpChargingProfile = json_tokener_parse(dataLine);
  12460. if(!is_error(SetChargingProfile))
  12461. {
  12462. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12463. {
  12464. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12465. {
  12466. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12467. }
  12468. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12469. {
  12470. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12471. }
  12472. }
  12473. }
  12474. json_object_put(tmpChargingProfile);
  12475. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12476. {
  12477. if(ChargingProfileAdded == FALSE)
  12478. {
  12479. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12480. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12481. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12482. ChargingProfileAdded = TRUE;
  12483. }
  12484. }
  12485. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12486. {
  12487. if(ChargingProfileAdded == FALSE)
  12488. {
  12489. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12490. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12491. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12492. ChargingProfileAdded = TRUE;
  12493. }
  12494. }
  12495. else
  12496. {
  12497. fprintf(outfile,"%s\n",dataLine);
  12498. if(ChargingProfileAdded == FALSE)
  12499. {
  12500. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12501. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12502. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12503. ChargingProfileAdded = TRUE;
  12504. }
  12505. }
  12506. } // end of while loop
  12507. fclose(infile);
  12508. fclose(outfile);
  12509. sprintf(rmFileCmd,"rm -f %s",filename);
  12510. system(rmFileCmd);
  12511. rename(tempfile, filename);
  12512. }
  12513. }
  12514. sleep(1);
  12515. result = TRUE;
  12516. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12517. }
  12518. end:
  12519. json_object_put(SetChargingProfile);
  12520. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12521. {
  12522. if(SetProfileReq.ConnectorId == 0)
  12523. {
  12524. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12525. {
  12526. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12527. }
  12528. }
  12529. else
  12530. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12531. }
  12532. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12533. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12534. return result;
  12535. }
  12536. int handleTriggerMessageRequest(char *uuid, char *payload)
  12537. {
  12538. mtrace();
  12539. int result = FAIL;
  12540. int connectorIdIsNULL = FALSE;
  12541. int connectorIdInt =0;
  12542. char sstr[40]={0},sstrtemp[100]={ 0 };
  12543. char requestedMessagestr[40]={0};
  12544. char comfirmstr[20]={0};
  12545. int c = 0;
  12546. char *loc;
  12547. DEBUG_INFO("handleTriggerMessageRequest\n");
  12548. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12549. strcpy(sstrtemp, stringtrimspace(payload));
  12550. c = 0;
  12551. loc = strstr(sstrtemp, "requestedMessage");
  12552. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12553. {
  12554. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12555. c++;
  12556. }
  12557. sstr[c] = '\0';
  12558. strcpy(requestedMessagestr, sstr);
  12559. c = 0;
  12560. loc = strstr(sstrtemp, "connectorId");
  12561. if(loc == NULL)
  12562. {
  12563. connectorIdIsNULL = TRUE;
  12564. }
  12565. else
  12566. {
  12567. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12568. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12569. {
  12570. sstr[c] = loc[strlen("connectorId")+2+c];
  12571. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12572. c++;
  12573. }
  12574. sstr[c] = '\0';
  12575. connectorIdInt = atoi(sstr);
  12576. }
  12577. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12578. {
  12579. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12580. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12581. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12582. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12583. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12584. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12585. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12586. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12587. {
  12588. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12589. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12590. return TRUE;
  12591. }
  12592. else
  12593. {
  12594. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12595. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12596. }
  12597. }
  12598. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12599. {
  12600. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12601. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12602. return TRUE;
  12603. }
  12604. //==========================
  12605. // Trigger message
  12606. //==========================
  12607. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12608. {
  12609. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12610. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12611. {
  12612. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12613. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12614. }
  12615. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12616. }
  12617. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12618. {
  12619. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12620. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12621. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12622. }
  12623. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12624. {
  12625. //sendBootNotificationRequest();
  12626. server_sign = FALSE;
  12627. }
  12628. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12629. {
  12630. refreshStartTimer(&clientTime.Heartbeat);
  12631. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12632. }
  12633. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12634. {
  12635. if(connectorIdIsNULL == FALSE)
  12636. {
  12637. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12638. {
  12639. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12640. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12641. }
  12642. }
  12643. else
  12644. {
  12645. for(int idx=0;idx< gunTotalNumber;idx++)
  12646. {
  12647. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12648. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12649. }
  12650. }
  12651. }
  12652. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12653. {
  12654. if(connectorIdIsNULL == FALSE)
  12655. {
  12656. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12657. {
  12658. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12659. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12660. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12661. }
  12662. }
  12663. else
  12664. {
  12665. for(int idx=0;idx< gunTotalNumber;idx++)
  12666. {
  12667. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12668. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12669. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12670. }
  12671. }
  12672. }
  12673. return result;
  12674. }
  12675. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12676. {
  12677. mtrace();
  12678. int result = FAIL;
  12679. int connectorIdInt =0;
  12680. char comfirmstr[20]={0};
  12681. int tempIndex = 0;
  12682. json_object *UnlockConnector;
  12683. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12684. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12685. UnlockConnector = json_tokener_parse(payload);
  12686. if(!is_error(UnlockConnector))
  12687. {
  12688. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12689. {
  12690. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12691. }
  12692. }
  12693. json_object_put(UnlockConnector);
  12694. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12695. if(gunTotalNumber == 0)
  12696. {
  12697. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12698. goto end;
  12699. }
  12700. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12701. {
  12702. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12703. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12704. goto end;
  12705. }
  12706. else
  12707. {
  12708. //check Transaction active
  12709. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12710. {
  12711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12712. {
  12713. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12714. }
  12715. else
  12716. {
  12717. tempIndex = connectorIdInt -1;
  12718. }
  12719. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12720. {
  12721. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12722. {
  12723. //stop Transaction
  12724. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12725. }
  12726. }
  12727. }
  12728. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12729. {
  12730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12731. {
  12732. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12733. }
  12734. else
  12735. {
  12736. tempIndex = connectorIdInt -1;
  12737. }
  12738. for (int index = 0; index < CCS_QUANTITY; index++)
  12739. {
  12740. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12741. {
  12742. //stop Transaction
  12743. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12744. }
  12745. }
  12746. }
  12747. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12748. {
  12749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12750. {
  12751. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12752. }
  12753. else
  12754. {
  12755. tempIndex = connectorIdInt -1;
  12756. }
  12757. for (int index = 0; index < GB_QUANTITY; index++)
  12758. {
  12759. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12760. {
  12761. //stop Transaction
  12762. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12763. }
  12764. }
  12765. }
  12766. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12767. {
  12768. tempIndex = connectorIdInt -1;
  12769. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12770. {
  12771. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12772. {
  12773. //stop Transaction
  12774. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12775. }
  12776. }
  12777. }
  12778. else
  12779. {
  12780. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12781. {
  12782. tempIndex = 2;
  12783. }
  12784. else
  12785. {
  12786. tempIndex = connectorIdInt-1;
  12787. }
  12788. for (int index = 0; index < AC_QUANTITY; index++)
  12789. {
  12790. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12791. {
  12792. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12793. }
  12794. }
  12795. }
  12796. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12797. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12798. result = TRUE;
  12799. return result;
  12800. }
  12801. end:
  12802. //json_object_put(obj); --- remove temporally
  12803. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12804. return result;
  12805. }
  12806. static char UpdateFirmwarepayloadData[300]={0};
  12807. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12808. {
  12809. mtrace();
  12810. int result = FAIL;
  12811. pthread_t t;
  12812. sendUpdateFirmwareConfirmation(uuid);
  12813. memset(UpdateFirmwarepayloadData, 0, 300);
  12814. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12815. if(!interLock.isUpdateFirmwareGoing)
  12816. {
  12817. interLock.isUpdateFirmwareGoing = 1;
  12818. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12819. sleep(1);
  12820. }
  12821. else
  12822. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12823. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12824. return result;
  12825. }
  12826. void *UpdateFirmwareProcess(void *data)
  12827. {
  12828. pthread_detach(pthread_self());
  12829. mtrace();
  12830. int retriesInt =0, retryIntervalInt=0;
  12831. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12832. int port=0;
  12833. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12834. int isSuccess = 0;
  12835. char ftpbuf[512];
  12836. char temp[100];
  12837. char * pch;
  12838. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12839. json_object *UpdateFirmware;
  12840. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12841. if(!is_error(UpdateFirmware))
  12842. {
  12843. // Required data
  12844. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12845. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12846. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12847. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12848. // Optional data
  12849. if(json_object_object_get(UpdateFirmware, "retries"))
  12850. {
  12851. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12852. }
  12853. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12854. {
  12855. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12856. }
  12857. }
  12858. json_object_put(UpdateFirmware);
  12859. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12860. memset(path, 0, ARRAY_SIZE(path));
  12861. // Wait retrieveData
  12862. if(strlen(retrieveDatestr) > 10)
  12863. {
  12864. do
  12865. {
  12866. sleep(1);
  12867. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12868. }
  12869. // Ready to download
  12870. system("rm -f /mnt/*");
  12871. if(strncmp(locationstr,"http", 4) == 0)
  12872. {
  12873. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12874. sprintf(ftppath,"/%s", path);
  12875. DEBUG_INFO("locationstr: %s\n", locationstr);
  12876. DEBUG_INFO("protocol: %s\n",protocol);
  12877. DEBUG_INFO("host: %s\n",host);
  12878. DEBUG_INFO("path: %s\n",path);
  12879. DEBUG_INFO("ftppath: %s\n",ftppath);
  12880. int ftppathlen=strlen(ftppath);
  12881. int i=1;
  12882. char filenametemp[50];
  12883. while(i < ftppathlen)
  12884. {
  12885. int len=ftppathlen-i;
  12886. if(ftppath[len]== 47) // '/' ascll code: 47
  12887. {
  12888. DEBUG_INFO("compare '/' all right\n");
  12889. break;
  12890. }
  12891. i=i+1;
  12892. }
  12893. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12894. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12895. filenametemp[i+1] = 0;
  12896. do
  12897. {
  12898. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12899. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12900. sleep(1);
  12901. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12902. if(!isSuccess)
  12903. {
  12904. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12905. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12906. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12907. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12908. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12909. }
  12910. else
  12911. {
  12912. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12913. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12914. }
  12915. retriesInt--;
  12916. }while((isSuccess == 0)&&(retriesInt >= 0));
  12917. }
  12918. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12919. {
  12920. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12921. memset(temp, 0, ARRAY_SIZE(temp));
  12922. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12923. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12924. int ftppathlen=strlen(ftpbuf);
  12925. int i=1;
  12926. char filenametemp[50];
  12927. while(i < ftppathlen)
  12928. {
  12929. int len=ftppathlen-i;
  12930. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12931. {
  12932. DEBUG_INFO(" compare '/' all right\n");
  12933. break;
  12934. }
  12935. i=i+1;
  12936. }
  12937. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12938. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12939. filenametemp[i+1] = 0;
  12940. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12941. pch=strchr(temp,'@');
  12942. if(pch==NULL)
  12943. {
  12944. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12945. protocol, host, &port, path);
  12946. strcpy(user,"anonymous");
  12947. strcpy(password,"");
  12948. }
  12949. else
  12950. {
  12951. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12952. protocol, user, password, host, &port, path);
  12953. }
  12954. sscanf(host,"%[^/]%s",host1, path1);
  12955. sprintf(ftppath,"%s", path1);
  12956. //DEBUG_INFO("protocol =%s\n",protocol);
  12957. //DEBUG_INFO("user =%s\n",user);
  12958. //DEBUG_INFO("password =%s\n",password);
  12959. //DEBUG_INFO("host1 =%s\n",host1);
  12960. //DEBUG_INFO("port =%d\n",port);
  12961. //DEBUG_INFO("path1 =%s\n",path1);
  12962. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12963. //ftpFile(host, user, password, port, ftppath, fname);
  12964. //download firmware pthred
  12965. if(port == 0)
  12966. {
  12967. port = 21;
  12968. }
  12969. do
  12970. {
  12971. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12972. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12973. sleep(1);
  12974. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12975. if(!isSuccess)
  12976. {
  12977. //BulldogUtil.sleepMs(interval*1000);
  12978. DEBUG_INFO("Update firmware request and download file fail.\n");
  12979. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12980. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12981. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12982. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12983. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12984. }
  12985. else
  12986. {
  12987. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12988. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12989. }
  12990. retriesInt--;
  12991. }while((!isSuccess)&&(retriesInt >= 0));
  12992. }
  12993. else
  12994. {
  12995. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12996. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12997. sleep(1);
  12998. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12999. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13000. }
  13001. // OCPPPH only, must announce CSU upgrade firmware
  13002. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13003. interLock.isUpdateFirmwareGoing = 0;
  13004. pthread_exit(NULL);
  13005. }
  13006. int handleCertificateSignedRequest(char *uuid, char *payload)
  13007. {
  13008. mtrace();
  13009. int result = PASS;
  13010. json_object *CertificateSigned;
  13011. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13012. CertificateSigned = json_tokener_parse(payload);
  13013. if(!is_error(CertificateSigned))
  13014. {
  13015. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13016. }
  13017. json_object_put(CertificateSigned);
  13018. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  13019. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  13020. fclose(fp);
  13021. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13022. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  13023. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  13024. sendCertificateSignedConfirmation(uuid);
  13025. return result;
  13026. }
  13027. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13028. {
  13029. mtrace();
  13030. int result = PASS;
  13031. json_object *DeleteCertificate;
  13032. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13033. DeleteCertificate = json_tokener_parse(payload);
  13034. if(!is_error(DeleteCertificate))
  13035. {
  13036. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13037. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13038. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13039. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13040. }
  13041. json_object_put(DeleteCertificate);
  13042. /*
  13043. * TODO: Delete certificateSigned process
  13044. */
  13045. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  13046. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  13047. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  13048. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  13049. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  13050. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  13051. sendDeleteCertificateConfirmation(uuid);
  13052. return result;
  13053. }
  13054. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13055. {
  13056. mtrace();
  13057. int result = PASS;
  13058. json_object *ExtendedTriggerMessage;
  13059. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13060. ExtendedTriggerMessage = json_tokener_parse(payload);
  13061. if(!is_error(ExtendedTriggerMessage))
  13062. {
  13063. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13064. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13065. {
  13066. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13067. }
  13068. else
  13069. {
  13070. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13071. }
  13072. }
  13073. json_object_put(ExtendedTriggerMessage);
  13074. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13075. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13076. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13077. {
  13078. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13079. }
  13080. else
  13081. {
  13082. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13083. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13084. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13085. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13086. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13087. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13088. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13089. {
  13090. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13091. }
  13092. else
  13093. {
  13094. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13095. }
  13096. }
  13097. sendExtendedTriggerMessageConfirmation(uuid);
  13098. //==========================
  13099. // Trigger message
  13100. //==========================
  13101. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13102. {
  13103. //sendBootNotificationRequest();
  13104. server_sign = FALSE;
  13105. }
  13106. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13107. {
  13108. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13109. }
  13110. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13111. {
  13112. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13113. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13114. {
  13115. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13116. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13117. }
  13118. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13119. }
  13120. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13121. {
  13122. refreshStartTimer(&clientTime.Heartbeat);
  13123. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13124. }
  13125. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13126. {
  13127. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13128. {
  13129. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13130. }
  13131. else
  13132. {
  13133. for(int idx=0;idx< gunTotalNumber;idx++)
  13134. {
  13135. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13136. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13137. }
  13138. }
  13139. }
  13140. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13141. {
  13142. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13143. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13144. {
  13145. 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\" &");
  13146. }
  13147. }
  13148. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13149. {
  13150. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13151. {
  13152. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13153. }
  13154. else
  13155. {
  13156. for(int idx=0;idx< gunTotalNumber;idx++)
  13157. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13158. }
  13159. }
  13160. return result;
  13161. }
  13162. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13163. {
  13164. mtrace();
  13165. int result = PASS;
  13166. json_object *GetInstalledCertificateIds;
  13167. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13168. GetInstalledCertificateIds = json_tokener_parse(payload);
  13169. if(!is_error(GetInstalledCertificateIds))
  13170. {
  13171. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13172. }
  13173. json_object_put(GetInstalledCertificateIds);
  13174. /*
  13175. * TODO: Return installed certificate process
  13176. */
  13177. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13178. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13179. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13180. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13181. sendGetInstalledCertificateIdsConfirmation(uuid);
  13182. return result;
  13183. }
  13184. int handleGetLogRequest(char *uuid, char *payload)
  13185. {
  13186. mtrace();
  13187. int result = PASS;
  13188. json_object *GetLog;
  13189. DEBUG_INFO("handleGetLogRequest...\n");
  13190. GetLog = json_tokener_parse(payload);
  13191. if(!is_error(GetLog))
  13192. {
  13193. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13194. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13195. if(json_object_object_get(GetLog, "retries") != NULL)
  13196. {
  13197. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13198. }
  13199. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13200. {
  13201. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13202. }
  13203. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13204. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13205. {
  13206. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13207. }
  13208. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13209. {
  13210. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13211. }
  13212. }
  13213. json_object_put(GetLog);
  13214. /*
  13215. * TODO: Upload log process
  13216. */
  13217. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13218. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13219. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13220. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13221. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13222. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13223. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13224. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13225. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13226. sendGetLogConfirmation(uuid);
  13227. return result;
  13228. }
  13229. int handleInstallCertificateRequest(char *uuid, char *payload)
  13230. {
  13231. mtrace();
  13232. int result = PASS;
  13233. json_object *InstallCertificate;
  13234. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13235. InstallCertificate = json_tokener_parse(payload);
  13236. if(!is_error(InstallCertificate))
  13237. {
  13238. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13239. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13240. /*
  13241. * TODO: Install certificate process
  13242. */
  13243. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13244. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13245. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13246. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13247. sendInstallCertificateConfirmation(uuid);
  13248. }
  13249. json_object_put(InstallCertificate);
  13250. return result;
  13251. }
  13252. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13253. {
  13254. mtrace();
  13255. int result = PASS;
  13256. json_object *SignedUpdateFirmware;
  13257. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13258. SignedUpdateFirmware = json_tokener_parse(payload);
  13259. if(!is_error(SignedUpdateFirmware))
  13260. {
  13261. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13262. {
  13263. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13264. }
  13265. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13266. {
  13267. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13268. }
  13269. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13270. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13271. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13272. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13273. {
  13274. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13275. }
  13276. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13277. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13278. }
  13279. json_object_put(SignedUpdateFirmware);
  13280. /*
  13281. * TODO: Upgrade firmware process
  13282. */
  13283. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13284. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13285. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13286. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13287. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13288. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13289. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13290. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13291. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13292. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13293. sendInstallCertificateConfirmation(uuid);
  13294. return result;
  13295. }
  13296. int handleUnknownRequest(char *uuid, char *payload)
  13297. {
  13298. mtrace();
  13299. int result = PASS;
  13300. DEBUG_INFO("handleUnknownRequest...\n");
  13301. sendUnknownConfirmation(uuid);
  13302. result = PASS;
  13303. return result;
  13304. }
  13305. //==========================================
  13306. // Handle server response routine
  13307. //==========================================
  13308. void handleAuthorizeResponse(char *payload, int gun_index)
  13309. {
  13310. mtrace();
  13311. char expiryDatestr[36]={0};
  13312. char parentIdTagstr[21]={0};
  13313. char statusstr[20]={0};
  13314. int expiryDateISNULL=FALSE;
  13315. int parentIdTagISNULL=FALSE;
  13316. DEBUG_INFO("handleAuthorizeResponse...\n");
  13317. json_object *Authorize;
  13318. Authorize = json_tokener_parse(payload);
  13319. if(!is_error(Authorize))
  13320. {
  13321. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13322. {
  13323. // Required data
  13324. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13325. // Optional data
  13326. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13327. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13328. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13329. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13330. }
  13331. }
  13332. json_object_put(Authorize);
  13333. if(expiryDateISNULL == FALSE)
  13334. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13335. if(parentIdTagISNULL == FALSE)
  13336. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13337. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13338. //Update idTag information to authorization cache if supproted
  13339. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13340. {
  13341. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13342. }
  13343. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13344. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13345. authorizeRetryTimes = 0;
  13346. }
  13347. void handleBootNotificationResponse(char *payload, int gun_index)
  13348. {
  13349. mtrace();
  13350. char statusStr[12]={0};
  13351. char currentTimeStr[30]={0};
  13352. int intervalInt = 0;
  13353. DEBUG_INFO("handleBootNotificationResponse...\n");
  13354. json_object *BootNotification;
  13355. BootNotification = json_tokener_parse(payload);
  13356. if(!is_error(BootNotification))
  13357. {
  13358. // Required data
  13359. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13360. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13361. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13362. }
  13363. json_object_put(BootNotification);
  13364. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13365. BootNotificationInterval = intervalInt;
  13366. //write back to ShmOCPP16DataPH->BootNotification
  13367. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13368. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13369. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13370. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13371. {
  13372. BootNotificationInterval = 0;
  13373. if((intervalInt == 0) || (intervalInt >= 10))
  13374. {
  13375. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13376. HeartBeatWaitTime = intervalInt;
  13377. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13378. }
  13379. server_sign = TRUE;
  13380. server_pending =FALSE;
  13381. }
  13382. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13383. {
  13384. server_pending = TRUE;
  13385. }
  13386. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13387. srand(time(NULL));
  13388. refreshStartTimer(&clientTime.Heartbeat);
  13389. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13390. SetOcppConnStatus(TRUE);
  13391. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13392. }
  13393. void handleDataTransferResponse(char *payload, int gun_index)
  13394. {
  13395. json_object *DataTransfer = json_tokener_parse(payload);
  13396. if(!is_error(DataTransfer))
  13397. {
  13398. // Required data
  13399. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13400. // Optional data
  13401. if(json_object_object_get(DataTransfer, "data") != NULL)
  13402. {
  13403. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13404. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13405. if(!is_error(Data))
  13406. {
  13407. if(json_object_object_get(Data, "msgId") != NULL)
  13408. {
  13409. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13410. {
  13411. 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")));
  13412. }
  13413. }
  13414. }
  13415. json_object_put(Data);
  13416. }
  13417. }
  13418. json_object_put(DataTransfer);
  13419. }
  13420. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13421. {
  13422. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13423. //struct json_object *obj;
  13424. // obj = json_tokener_parse(payload);
  13425. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13426. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13427. //No fields are defined.
  13428. }
  13429. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13430. {
  13431. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13432. //struct json_object *obj;
  13433. // obj = json_tokener_parse(payload);
  13434. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13435. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13436. //No fields are defined.
  13437. }
  13438. void handleHeartbeatResponse(char *payload, int gun_index)
  13439. {
  13440. mtrace();
  13441. DEBUG_INFO("handleHeartbeatResponse...\n");
  13442. json_object *Heartbeat;
  13443. Heartbeat = json_tokener_parse(payload);
  13444. if(!is_error(Heartbeat))
  13445. {
  13446. // Required data
  13447. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13448. }
  13449. json_object_put(Heartbeat);
  13450. if(FirstHeartBeat == 0)
  13451. {
  13452. FirstHeartBeat = 1;
  13453. DEBUG_INFO("FirstHeartBeat \n");
  13454. }
  13455. HeartBeatWithNOResponse = 0;
  13456. refreshStartTimer(&clientTime.Heartbeat);
  13457. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13458. }
  13459. void handleMeterValuesResponse(char *payload, int gun_index)
  13460. {
  13461. mtrace();
  13462. DEBUG_INFO("handleMeterValuesResponse...\n");
  13463. isQueueSendable = 1;
  13464. }
  13465. void handleStartTransactionResponse(char *payload, int gun_index)
  13466. {
  13467. mtrace();
  13468. //int transactionIdInt = 0;
  13469. FILE *outfile;
  13470. char data[100]={0};
  13471. DEBUG_INFO("handleStartTransactionResponse...\n");
  13472. json_object *StartTransaction;
  13473. StartTransaction = json_tokener_parse(payload);
  13474. if(!is_error(StartTransaction))
  13475. {
  13476. // Required data
  13477. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13478. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13479. // Optional data
  13480. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13481. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13482. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13483. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13484. }
  13485. json_object_put(StartTransaction);
  13486. isQueueSendable = 1;
  13487. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13488. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13489. //-----------Start : write to the Queue TransactionId file -----------------//
  13490. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13491. {}
  13492. else
  13493. {
  13494. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13495. if(log == NULL)
  13496. {
  13497. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13498. return ;
  13499. }
  13500. else
  13501. {
  13502. fclose(log);
  13503. }
  13504. }
  13505. // open file for writing
  13506. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13507. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13508. {
  13509. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13510. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13511. fputs(data, outfile);
  13512. fclose (outfile);
  13513. }
  13514. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13515. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13516. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13517. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13518. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13519. }
  13520. void handleStatusNotificationResponse(char *payload, int gun_index)
  13521. {
  13522. mtrace();
  13523. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13524. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13525. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13526. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13527. }
  13528. void handleStopTransactionnResponse(char *payload, int gun_index)
  13529. {
  13530. mtrace();
  13531. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13532. json_object *StopTransaction;
  13533. StopTransaction = json_tokener_parse(payload);
  13534. if(!is_error(StopTransaction))
  13535. {
  13536. // Optional data
  13537. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13538. {
  13539. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13540. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13541. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13542. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13543. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13544. }
  13545. }
  13546. json_object_put(StopTransaction);
  13547. isQueueSendable = 1;
  13548. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13549. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13550. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13551. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13552. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13553. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13554. }
  13555. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13556. {
  13557. mtrace();
  13558. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13559. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13560. }
  13561. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13562. {
  13563. mtrace();
  13564. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13565. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13566. }
  13567. void handleSignCertificateResponse(char *payload, int gun_index)
  13568. {
  13569. mtrace();
  13570. DEBUG_INFO("handleSignCertificateResponse...\n");
  13571. json_object *SignCertificate;
  13572. SignCertificate = json_tokener_parse(payload);
  13573. if(!is_error(SignCertificate))
  13574. {
  13575. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13576. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13577. }
  13578. json_object_put(SignCertificate);
  13579. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13580. }
  13581. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13582. {
  13583. mtrace();
  13584. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13585. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13586. }
  13587. //==========================================
  13588. // Handle Error routine
  13589. //==========================================
  13590. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13591. {
  13592. mtrace();
  13593. #ifdef SystemLogMessage
  13594. DEBUG_INFO("errorCode: %s\n", errorCode);
  13595. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13596. DEBUG_INFO("errorDetails: %s\n", payload);
  13597. #endif
  13598. }
  13599. //===============================================
  13600. // Common routine
  13601. //===============================================
  13602. int initialConfigurationTable(void)
  13603. {
  13604. //clock_t start_t, end_t, total_t;
  13605. FILE *fp;
  13606. FILE *outfile;
  13607. char str[512]={0};
  13608. char sstr[256]={0};
  13609. int c = 0;
  13610. char *loc;
  13611. int confVersion = 14;
  13612. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13613. //start_t = clock();
  13614. //printf("Starting of the program, start_t = %ld\n", start_t);
  13615. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13616. // Check configuration file size is correct
  13617. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13618. {
  13619. struct stat st;
  13620. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13621. if(st.st_size < 3100)
  13622. {
  13623. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13624. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13625. }
  13626. }
  13627. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13628. {
  13629. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13630. if(outfile == NULL)
  13631. {
  13632. DEBUG_INFO("Error opening file\n");
  13633. return FALSE;
  13634. }
  13635. /*Core Profile*/
  13636. //AllowOfflineTxForUnknownId
  13637. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13638. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13639. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13641. //AuthorizationCacheEnabled
  13642. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13643. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13644. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13646. //AuthorizeRemoteTxRequests
  13647. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13648. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13649. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13651. //BlinkRepeat
  13652. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13653. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13654. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13656. //ClockAlignedDataInterval
  13657. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13658. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13659. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13661. //ConnectionTimeOut
  13662. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13663. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13664. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13666. //GetConfigurationMaxKeys
  13667. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13668. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13669. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13671. // HeartbeatInterval
  13672. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13673. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13674. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13676. // LightIntensity
  13677. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13678. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13679. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13681. // LocalAuthorizeOffline
  13682. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13683. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13684. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13686. // LocalPreAuthorize
  13687. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13688. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13689. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13691. // MaxEnergyOnInvalidId
  13692. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13693. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13694. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13696. // MeterValuesAlignedData
  13697. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13698. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13699. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13700. 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" );
  13701. else
  13702. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13704. // MeterValuesAlignedDataMaxLength
  13705. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13706. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13707. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13708. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13709. else
  13710. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13712. // MeterValuesSampledData
  13713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13714. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13715. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13716. 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" );
  13717. else
  13718. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13720. // MeterValuesSampledDataMaxLength
  13721. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13722. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13723. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13724. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13725. else
  13726. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13728. // MeterValueSampleInterval
  13729. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13730. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13731. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13733. // MinimumStatusDuration
  13734. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13735. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13736. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13737. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13739. // NumberOfConnectors
  13740. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13741. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13742. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13743. {
  13744. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13745. }
  13746. else
  13747. {
  13748. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13749. }
  13750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13751. // ResetRetries
  13752. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13753. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13754. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13756. // ConnectorPhaseRotation
  13757. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13758. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13759. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13761. // ConnectorPhaseRotationMaxLength
  13762. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13763. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13764. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13766. // StopTransactionOnEVSideDisconnect
  13767. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13768. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13769. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13771. // StopTransactionOnInvalidId
  13772. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13773. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13774. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13776. // StopTxnAlignedData
  13777. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13778. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13779. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13781. // StopTxnAlignedDataMaxLength
  13782. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13783. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13784. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13786. // StopTxnSampledData
  13787. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13788. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13789. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13790. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13791. else
  13792. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13794. // StopTxnSampledDataMaxLength
  13795. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13796. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13797. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13798. {
  13799. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13800. }
  13801. else
  13802. {
  13803. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13804. }
  13805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13806. // SupportedFeatureProfiles
  13807. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13808. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13809. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13811. // SupportedFeatureProfilesMaxLength
  13812. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13813. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13814. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13816. // TransactionMessageAttempts
  13817. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13818. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13820. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13822. // TransactionMessageRetryInterval
  13823. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13824. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13825. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13826. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13828. // UnlockConnectorOnEVSideDisconnect
  13829. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13833. // WebSocketPingInterval
  13834. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13835. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13836. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13838. // QueueOffLineMeterValues
  13839. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13841. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13843. // AuthorizationKey
  13844. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13846. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13848. // SecurityProfile
  13849. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13851. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13853. // DefaultPrice
  13854. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13856. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13858. // CustomDisplayCostAndPrice
  13859. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13860. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13863. // CustomIdleFeeAfterStop
  13864. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13868. // SystemUptimeSec
  13869. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13870. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13871. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13873. // FreeVend
  13874. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13878. // FreeVendIdtag
  13879. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13880. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13881. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13883. // OcppServer
  13884. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13885. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13886. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13888. // MaintainServer
  13889. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13891. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13893. // StatusNotificationPeriodically
  13894. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13895. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13898. // StatusNotificationInterval
  13899. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13900. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13901. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13903. // isEnableLocalPowerSharing
  13904. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  13905. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  13906. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  13907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  13908. // PowerSharingServerIP
  13909. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  13910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  13911. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  13912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  13913. // EVCCID_PREFIX
  13914. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  13915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  13916. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  13917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  13918. // Configuration Version
  13919. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13920. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13921. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13923. //* Local Auth List Management Profile*/
  13924. #if 0
  13925. //For OCTT Test Case
  13926. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13927. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13929. #endif
  13930. #if 1
  13931. //LocalAuthListEnabled
  13932. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13934. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13936. #endif
  13937. //LocalAuthListMaxLength
  13938. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13940. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13942. //SendLocalListMaxLength
  13943. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13944. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13947. //ReserveConnectorZeroSupported
  13948. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13949. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13950. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13951. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13952. //* Smart Charging Profile */
  13953. //ChargeProfileMaxStackLevel
  13954. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13955. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13956. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13958. // ChargingScheduleAllowedChargingRateUnit
  13959. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13963. // ChargingScheduleMaxPeriods
  13964. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13965. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13968. // ConnectorSwitch3to1PhaseSupported
  13969. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13973. // MaxChargingProfilesInstalled
  13974. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13975. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13976. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13978. fclose(outfile);
  13979. }
  13980. else
  13981. {
  13982. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13983. char keystr[60]={0};
  13984. char readonlystr[10]={0};
  13985. char valuestr[256]={0};
  13986. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13987. if(fp == NULL) {
  13988. DEBUG_INFO("Error opening file");
  13989. return FALSE;
  13990. }
  13991. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13992. {
  13993. //DEBUG_INFO("Get Configuration \n");
  13994. if(strlen(str) > 0)
  13995. {
  13996. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13997. //*************************key*********************************/
  13998. if(strstr(str, "key") != NULL)
  13999. {
  14000. loc = strstr(str, "key");
  14001. c = 0;
  14002. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14003. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14004. {
  14005. sstr[c] = loc[strlen("key")+3+c];
  14006. c++;
  14007. }
  14008. sstr[c] = '\0';
  14009. strcpy(keystr,sstr);
  14010. }
  14011. //*************************readonly*********************************/
  14012. if(strstr(str, "readonly") != NULL)
  14013. {
  14014. loc = strstr(str, "readonly");
  14015. c = 0;
  14016. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14017. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14018. {
  14019. sstr[c] = loc[strlen("readonly")+2+c];
  14020. c++;
  14021. }
  14022. sstr[c] = '\0';
  14023. strcpy(readonlystr,sstr);
  14024. }
  14025. //*************************value*********************************/
  14026. if(strstr(str, "value") != NULL)
  14027. {
  14028. loc = strstr(str, "value");
  14029. c = 0;
  14030. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14031. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14032. {
  14033. sstr[c] = loc[strlen("value")+3+c];
  14034. c++;
  14035. }
  14036. sstr[c] = '\0';
  14037. strcpy(valuestr,sstr);
  14038. }
  14039. // DEBUG_INFO("keystr=%s\n",keystr);
  14040. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14041. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14042. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14043. {
  14044. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14045. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14046. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14047. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14048. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14049. }
  14050. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14051. {
  14052. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14053. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14054. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14055. }
  14056. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14057. {
  14058. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14059. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14060. }
  14061. if(strcmp(keystr, "BlinkRepeat") == 0)
  14062. {
  14063. //Charger.BlinkRepeat = Integer.parseInt(value);
  14064. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14065. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14066. }
  14067. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14068. {
  14069. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14070. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14071. }
  14072. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14073. {
  14074. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14075. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14076. }
  14077. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14078. {
  14079. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14080. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14081. }
  14082. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14083. {
  14084. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14085. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14086. HeartBeatWaitTime = atoi(valuestr);
  14087. }
  14088. if(strcmp(keystr, "LightIntensity") == 0)
  14089. {
  14090. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14091. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14092. }
  14093. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14094. {
  14095. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14096. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14097. }
  14098. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14099. {
  14100. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14101. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14102. }
  14103. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14104. {
  14105. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14106. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14107. }
  14108. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14109. {
  14110. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14111. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14112. }
  14113. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14114. {
  14115. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14116. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14117. }
  14118. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14119. {
  14120. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14121. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14122. }
  14123. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14124. {
  14125. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14126. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14127. }
  14128. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14129. {
  14130. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14131. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14132. }
  14133. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14134. {
  14135. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14136. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14137. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14138. }
  14139. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14140. {
  14141. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14142. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14143. }
  14144. if(strcmp(keystr, "ResetRetries") == 0)
  14145. {
  14146. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14147. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14148. }
  14149. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14150. {
  14151. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14152. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14153. }
  14154. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14155. {
  14156. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14157. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14158. }
  14159. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14160. {
  14161. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14162. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14163. }
  14164. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14165. {
  14166. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14167. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14168. }
  14169. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14170. {
  14171. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14172. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14173. }
  14174. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14175. {
  14176. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14177. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14178. }
  14179. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14180. {
  14181. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14182. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14183. }
  14184. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14185. {
  14186. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14187. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14188. }
  14189. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14190. {
  14191. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14192. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14193. }
  14194. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14195. {
  14196. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14197. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14198. }
  14199. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14200. {
  14201. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14202. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14203. TransactionMessageAttemptsValue = atoi(valuestr);
  14204. }
  14205. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14206. {
  14207. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14208. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14209. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14210. }
  14211. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14212. {
  14213. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14214. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14215. }
  14216. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14217. {
  14218. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14219. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14220. }
  14221. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14222. {
  14223. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14224. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14225. }
  14226. if(strcmp(keystr, "AuthorizationKey") == 0)
  14227. {
  14228. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14229. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14230. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14231. }
  14232. if(strcmp(keystr, "SecurityProfile") == 0)
  14233. {
  14234. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14235. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14236. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14237. }
  14238. if(strcmp(keystr, "DefaultPrice") == 0)
  14239. {
  14240. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14241. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14242. }
  14243. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14244. {
  14245. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14246. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14247. }
  14248. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14249. {
  14250. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14251. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14252. }
  14253. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14254. {
  14255. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14256. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14257. }
  14258. if(strcmp(keystr, "FreeVend") == 0)
  14259. {
  14260. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14261. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14262. }
  14263. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14264. {
  14265. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14266. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14267. }
  14268. if(strcmp(keystr, "OcppServer") == 0)
  14269. {
  14270. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14271. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14272. }
  14273. if(strcmp(keystr, "MaintainServer") == 0)
  14274. {
  14275. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14276. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14277. }
  14278. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14279. {
  14280. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14281. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14282. }
  14283. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14284. {
  14285. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14286. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14287. }
  14288. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14289. {
  14290. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14291. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14292. }
  14293. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14294. {
  14295. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14296. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14297. }
  14298. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14299. {
  14300. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14301. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14302. }
  14303. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14304. {
  14305. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14306. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14307. }
  14308. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14309. {
  14310. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14311. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14312. }
  14313. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14314. {
  14315. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14316. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14317. }
  14318. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14319. {
  14320. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14321. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14322. }
  14323. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14324. {
  14325. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14326. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14327. }
  14328. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14329. {
  14330. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14331. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14332. }
  14333. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14334. {
  14335. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14336. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14337. }
  14338. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14339. {
  14340. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14341. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14342. }
  14343. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14344. {
  14345. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14346. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14347. }
  14348. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14349. {
  14350. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14351. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14352. }
  14353. }
  14354. }
  14355. fclose(fp);
  14356. }
  14357. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14358. {
  14359. return PASS;
  14360. }
  14361. else
  14362. {
  14363. return FAIL;
  14364. }
  14365. }
  14366. void StoreConfigurationTable(void)
  14367. {
  14368. FILE *outfile;
  14369. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14370. if(outfile == NULL)
  14371. {
  14372. DEBUG_INFO("Error opening file");
  14373. return ;
  14374. }
  14375. /*Core Profile*/
  14376. //AllowOfflineTxForUnknownId
  14377. /*
  14378. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14379. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14380. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14381. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14382. */
  14383. //DEBUG_INFO("data=%s\n",data);
  14384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14385. //AuthorizationCacheEnabled
  14386. /*
  14387. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14388. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14390. */
  14391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14392. //AuthorizeRemoteTxRequests
  14393. /*
  14394. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14395. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14396. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14397. */
  14398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14399. //BlinkRepeat
  14400. /*
  14401. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14402. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14404. */
  14405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14406. //ClockAlignedDataInterval
  14407. /*
  14408. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14409. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14410. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14411. */
  14412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14413. //ConnectionTimeOut
  14414. /*
  14415. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14416. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14418. */
  14419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14420. //GetConfigurationMaxKeys
  14421. /*
  14422. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14423. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14424. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14425. */
  14426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14427. // HeartbeatInterval
  14428. /*
  14429. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14430. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14431. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14432. */
  14433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14434. // LightIntensity
  14435. /*
  14436. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14437. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14439. */
  14440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14441. // LocalAuthorizeOffline
  14442. /*
  14443. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14444. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14445. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14446. */
  14447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14448. // LocalPreAuthorize
  14449. /*
  14450. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14451. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14452. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14453. */
  14454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14455. // MaxEnergyOnInvalidId
  14456. /*
  14457. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14458. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14459. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14460. */
  14461. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14462. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14463. // MeterValuesAlignedData
  14464. /*
  14465. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14466. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14467. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14468. */
  14469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14470. // MeterValuesAlignedDataMaxLength
  14471. /*
  14472. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14473. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14474. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14475. */
  14476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14477. // MeterValuesSampledData
  14478. /*
  14479. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14480. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14481. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14482. */
  14483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14484. // MeterValuesSampledDataMaxLength
  14485. /*
  14486. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14487. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14488. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14489. */
  14490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14491. // MeterValueSampleInterval
  14492. /*
  14493. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14494. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14495. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14496. */
  14497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14498. // MinimumStatusDuration
  14499. /*
  14500. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14501. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14502. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14503. */
  14504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14505. // NumberOfConnectors
  14506. /*
  14507. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14508. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14509. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14510. {
  14511. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14512. }
  14513. else
  14514. {
  14515. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14516. }
  14517. */
  14518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14519. // ResetRetries
  14520. /*
  14521. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14522. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14523. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14524. */
  14525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14526. // ConnectorPhaseRotation
  14527. /*
  14528. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14529. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14530. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14531. */
  14532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14533. // ConnectorPhaseRotationMaxLength
  14534. /*
  14535. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14536. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14537. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14538. */
  14539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14540. // StopTransactionOnEVSideDisconnect
  14541. /*
  14542. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14543. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14544. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14545. */
  14546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14547. // StopTransactionOnInvalidId
  14548. /*
  14549. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14550. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14551. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14552. */
  14553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14554. // StopTxnAlignedData
  14555. /*
  14556. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14557. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14558. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14559. */
  14560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14561. // StopTxnAlignedDataMaxLength
  14562. /*
  14563. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14564. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14565. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14566. */
  14567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14568. // StopTxnSampledData
  14569. /*
  14570. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14571. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14572. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14573. */
  14574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14575. // StopTxnSampledDataMaxLength
  14576. /*
  14577. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14578. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14579. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14580. */
  14581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14582. // SupportedFeatureProfiles
  14583. /*
  14584. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14585. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14586. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14587. */
  14588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14589. // SupportedFeatureProfilesMaxLength
  14590. /*
  14591. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14592. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14593. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14594. */
  14595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14596. // TransactionMessageAttempts
  14597. /*
  14598. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14599. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14600. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14601. */
  14602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14603. // TransactionMessageRetryInterval
  14604. /*
  14605. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14606. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14607. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14608. */
  14609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14610. // UnlockConnectorOnEVSideDisconnect
  14611. /*
  14612. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14613. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14614. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14615. */
  14616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14617. // WebSocketPingInterval
  14618. /*
  14619. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14620. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14621. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14622. */
  14623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14624. // QueueOffLineMeterValues
  14625. /*
  14626. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14627. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14628. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14629. */
  14630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14631. // AuthorizationKey
  14632. /*
  14633. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14634. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14635. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14636. */
  14637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14638. // SecurityProfile
  14639. /*
  14640. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14641. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14642. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14643. */
  14644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14645. // DefaultPrice
  14646. /*
  14647. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14648. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14649. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14650. */
  14651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14652. // CustomDisplayCostAndPrice
  14653. /*
  14654. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14655. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14656. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14657. */
  14658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14659. // CustomIdleFeeAfterStop
  14660. /*
  14661. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14662. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14663. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14664. */
  14665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14666. // SystemUptimeSec
  14667. /*
  14668. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14669. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14670. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14671. */
  14672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14673. // FreeVend
  14674. /*
  14675. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14676. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14677. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14678. */
  14679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14680. // FreeVendIdtag
  14681. /*
  14682. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14683. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14684. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14685. */
  14686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14687. // OcppServer
  14688. /*
  14689. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14690. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14691. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14692. */
  14693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14694. // MaintainServer
  14695. /*
  14696. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14697. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14698. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14699. */
  14700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14701. // StatusNotificationPeriodically
  14702. /*
  14703. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14704. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14705. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14706. */
  14707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14708. // StatusNotificationInterval
  14709. /*
  14710. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14711. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14712. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14713. */
  14714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14715. // isEnableLocalPowerSharing
  14716. /*
  14717. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  14720. */
  14721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14722. // PowerSharingServerIP
  14723. /*
  14724. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  14727. */
  14728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14729. // EVCCID_PREFIX
  14730. /*
  14731. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14734. */
  14735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14736. // ConfigurationVersion
  14737. /*
  14738. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14739. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14740. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14741. */
  14742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14743. //* Local Auth List Management Profile*/
  14744. //LocalAuthListEnabled
  14745. /*
  14746. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14747. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14748. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14749. */
  14750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14751. //LocalAuthListMaxLength
  14752. /*
  14753. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14754. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14755. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14756. */
  14757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14758. //SendLocalListMaxLength
  14759. /*
  14760. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14761. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14762. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14763. */
  14764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14765. //ReserveConnectorZeroSupported
  14766. /*
  14767. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14768. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14769. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14770. */
  14771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14772. //* Smart Charging Profile */
  14773. //ChargeProfileMaxStackLevel
  14774. /*
  14775. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14776. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14777. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14778. */
  14779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14780. // ChargingScheduleAllowedChargingRateUnit
  14781. /*
  14782. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14783. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14784. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14785. */
  14786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14787. // ChargingScheduleMaxPeriods
  14788. /*
  14789. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14790. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14791. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14792. */
  14793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14794. // ConnectorSwitch3to1PhaseSupported
  14795. /*
  14796. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14797. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14798. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14799. */
  14800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14801. // MaxChargingProfilesInstalled
  14802. /*
  14803. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14804. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14806. */
  14807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14808. fclose(outfile);
  14809. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14810. }
  14811. void getKeyValue(char *keyReq)
  14812. {
  14813. int isEmpty = FALSE;
  14814. int isKnowKey = FALSE;
  14815. DEBUG_INFO("keyReq = %s\n", keyReq);
  14816. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14817. isEmpty = TRUE;
  14818. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14819. {
  14820. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14822. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14823. {
  14824. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14825. }
  14826. else
  14827. {
  14828. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14829. }
  14830. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14831. isKnowKey = TRUE;
  14832. }
  14833. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14834. {
  14835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14837. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14838. {
  14839. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14840. }
  14841. else
  14842. {
  14843. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14844. }
  14845. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14846. isKnowKey = TRUE;
  14847. }
  14848. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14849. {
  14850. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14852. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14853. {
  14854. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14855. }
  14856. else
  14857. {
  14858. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14859. }
  14860. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14861. isKnowKey = TRUE;
  14862. }
  14863. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14864. {
  14865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14866. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14867. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14868. {
  14869. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14870. }
  14871. else
  14872. {
  14873. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14874. }
  14875. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14876. isKnowKey = TRUE;
  14877. }
  14878. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14879. {
  14880. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14882. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14883. {
  14884. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14885. }
  14886. else
  14887. {
  14888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14889. }
  14890. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14891. isKnowKey = TRUE;
  14892. }
  14893. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14894. {
  14895. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14897. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14898. {
  14899. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14900. }
  14901. else
  14902. {
  14903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14904. }
  14905. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14906. isKnowKey = TRUE;
  14907. }
  14908. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14909. {
  14910. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14912. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14913. {
  14914. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14915. }
  14916. else
  14917. {
  14918. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14919. }
  14920. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14921. isKnowKey = TRUE;
  14922. }
  14923. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14924. {
  14925. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14927. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14928. {
  14929. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14930. }
  14931. else
  14932. {
  14933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14934. }
  14935. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14936. isKnowKey = TRUE;
  14937. }
  14938. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14939. {
  14940. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14941. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14942. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14943. {
  14944. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14945. }
  14946. else
  14947. {
  14948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14949. }
  14950. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14951. isKnowKey = TRUE;
  14952. }
  14953. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14954. {
  14955. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14957. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14958. {
  14959. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14960. }
  14961. else
  14962. {
  14963. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14964. }
  14965. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14966. isKnowKey = TRUE;
  14967. }
  14968. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14969. {
  14970. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14971. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14972. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14973. {
  14974. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14975. }
  14976. else
  14977. {
  14978. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14979. }
  14980. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14981. isKnowKey = TRUE;
  14982. }
  14983. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14984. {
  14985. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14986. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14987. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14988. {
  14989. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14990. }
  14991. else
  14992. {
  14993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14994. }
  14995. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14996. isKnowKey = TRUE;
  14997. }
  14998. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14999. {
  15000. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15001. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15002. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15003. {
  15004. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15005. }
  15006. else
  15007. {
  15008. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15009. }
  15010. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15011. isKnowKey = TRUE;
  15012. }
  15013. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15014. {
  15015. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15016. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15017. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15018. {
  15019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15020. }
  15021. else
  15022. {
  15023. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15024. }
  15025. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15026. isKnowKey = TRUE;
  15027. }
  15028. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15029. {
  15030. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15031. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15032. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15033. {
  15034. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15035. }
  15036. else
  15037. {
  15038. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15039. }
  15040. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15041. isKnowKey = TRUE;
  15042. }
  15043. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15044. {
  15045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15047. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15048. {
  15049. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15050. }
  15051. else
  15052. {
  15053. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15054. }
  15055. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15056. isKnowKey = TRUE;
  15057. }
  15058. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15059. {
  15060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15062. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15063. {
  15064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15065. }
  15066. else
  15067. {
  15068. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15069. }
  15070. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15071. isKnowKey = TRUE;
  15072. }
  15073. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15074. {
  15075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15077. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15078. {
  15079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15080. }
  15081. else
  15082. {
  15083. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15084. }
  15085. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  15086. isKnowKey = TRUE;
  15087. }
  15088. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15089. {
  15090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15091. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15092. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15093. {
  15094. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15095. }
  15096. else
  15097. {
  15098. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15099. }
  15100. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15101. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15102. isKnowKey = TRUE;
  15103. }
  15104. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15105. {
  15106. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15107. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15108. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15109. {
  15110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15111. }
  15112. else
  15113. {
  15114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15115. }
  15116. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15117. isKnowKey = TRUE;
  15118. }
  15119. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15120. {
  15121. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15122. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15123. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15124. {
  15125. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15126. }
  15127. else
  15128. {
  15129. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15130. }
  15131. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15132. isKnowKey = TRUE;
  15133. }
  15134. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15135. {
  15136. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15137. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15138. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15139. {
  15140. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15141. }
  15142. else
  15143. {
  15144. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15145. }
  15146. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15147. isKnowKey = TRUE;
  15148. }
  15149. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15150. {
  15151. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15152. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15153. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15154. {
  15155. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15156. }
  15157. else
  15158. {
  15159. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15160. }
  15161. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15162. isKnowKey = TRUE;
  15163. }
  15164. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15165. {
  15166. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15167. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15168. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15169. {
  15170. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15171. }
  15172. else
  15173. {
  15174. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15175. }
  15176. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15177. isKnowKey = TRUE;
  15178. }
  15179. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15180. {
  15181. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15182. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15183. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15184. {
  15185. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15186. }
  15187. else
  15188. {
  15189. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15190. }
  15191. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15192. isKnowKey = TRUE;
  15193. }
  15194. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15195. {
  15196. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15197. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15198. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15199. {
  15200. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15201. }
  15202. else
  15203. {
  15204. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15205. }
  15206. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15207. isKnowKey = TRUE;
  15208. }
  15209. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15210. {
  15211. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15212. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15213. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15214. {
  15215. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15216. }
  15217. else
  15218. {
  15219. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15220. }
  15221. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15222. isKnowKey = TRUE;
  15223. }
  15224. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15225. {
  15226. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15227. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15228. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15229. {
  15230. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15231. }
  15232. else
  15233. {
  15234. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15235. }
  15236. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15237. isKnowKey = TRUE;
  15238. }
  15239. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15240. {
  15241. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15242. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15243. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15244. {
  15245. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15246. }
  15247. else
  15248. {
  15249. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15250. }
  15251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15252. isKnowKey = TRUE;
  15253. }
  15254. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15255. {
  15256. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15257. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15258. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15259. {
  15260. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15261. }
  15262. else
  15263. {
  15264. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15265. }
  15266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15267. isKnowKey = TRUE;
  15268. }
  15269. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15270. {
  15271. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15272. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15273. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15274. {
  15275. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15276. }
  15277. else
  15278. {
  15279. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15280. }
  15281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15282. isKnowKey = TRUE;
  15283. }
  15284. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15285. {
  15286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15287. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15288. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15289. {
  15290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15291. }
  15292. else
  15293. {
  15294. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15295. }
  15296. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15297. isKnowKey = TRUE;
  15298. }
  15299. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15300. {
  15301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15303. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15304. {
  15305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15306. }
  15307. else
  15308. {
  15309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15310. }
  15311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15312. isKnowKey = TRUE;
  15313. }
  15314. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15315. {
  15316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15318. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15319. {
  15320. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15321. }
  15322. else
  15323. {
  15324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15325. }
  15326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15327. isKnowKey = TRUE;
  15328. }
  15329. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15330. {
  15331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15333. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15334. {
  15335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15336. }
  15337. else
  15338. {
  15339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15340. }
  15341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15342. isKnowKey = TRUE;
  15343. }
  15344. /*
  15345. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15346. {
  15347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15349. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15350. {
  15351. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15352. }
  15353. else
  15354. {
  15355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15356. }
  15357. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15358. isKnowKey = TRUE;
  15359. }*/
  15360. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15361. {
  15362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15364. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15365. {
  15366. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15367. }
  15368. else
  15369. {
  15370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15371. }
  15372. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15373. isKnowKey = TRUE;
  15374. }
  15375. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15376. {
  15377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15379. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15380. {
  15381. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15382. }
  15383. else
  15384. {
  15385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15386. }
  15387. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15388. isKnowKey = TRUE;
  15389. }
  15390. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15391. {
  15392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15394. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15395. {
  15396. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15397. }
  15398. else
  15399. {
  15400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15401. }
  15402. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15403. isKnowKey = TRUE;
  15404. }
  15405. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15406. {
  15407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15409. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15410. {
  15411. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15412. }
  15413. else
  15414. {
  15415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15416. }
  15417. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15418. isKnowKey = TRUE;
  15419. }
  15420. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15421. {
  15422. struct sysinfo s_info;
  15423. int error = sysinfo(&s_info);
  15424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15426. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15427. {
  15428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15429. }
  15430. else
  15431. {
  15432. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15433. }
  15434. if(error != 0)
  15435. {
  15436. DEBUG_WARN("System uptime get error: %d\n", error);
  15437. }
  15438. else
  15439. {
  15440. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15441. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15442. }
  15443. isKnowKey = TRUE;
  15444. }
  15445. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15446. {
  15447. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15449. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15450. {
  15451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15452. }
  15453. else
  15454. {
  15455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15456. }
  15457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15458. isKnowKey = TRUE;
  15459. }
  15460. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15461. {
  15462. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15464. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15465. {
  15466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15467. }
  15468. else
  15469. {
  15470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15471. }
  15472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15473. isKnowKey = TRUE;
  15474. }
  15475. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15476. {
  15477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15479. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15480. {
  15481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15482. }
  15483. else
  15484. {
  15485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15486. }
  15487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15488. isKnowKey = TRUE;
  15489. }
  15490. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15491. {
  15492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15494. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15495. {
  15496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15497. }
  15498. else
  15499. {
  15500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15501. }
  15502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15503. isKnowKey = TRUE;
  15504. }
  15505. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15506. {
  15507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15508. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15509. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15510. {
  15511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15512. }
  15513. else
  15514. {
  15515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15516. }
  15517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15518. isKnowKey = TRUE;
  15519. }
  15520. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15521. {
  15522. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15524. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15525. {
  15526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15527. }
  15528. else
  15529. {
  15530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15531. }
  15532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15533. isKnowKey = TRUE;
  15534. }
  15535. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  15536. {
  15537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  15538. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  15539. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  15540. {
  15541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  15542. }
  15543. else
  15544. {
  15545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  15546. }
  15547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  15548. isKnowKey = TRUE;
  15549. }
  15550. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  15551. {
  15552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  15553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  15554. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  15555. {
  15556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  15557. }
  15558. else
  15559. {
  15560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  15561. }
  15562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  15563. isKnowKey = TRUE;
  15564. }
  15565. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  15566. {
  15567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  15568. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  15569. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  15570. {
  15571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  15572. }
  15573. else
  15574. {
  15575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  15576. }
  15577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  15578. isKnowKey = TRUE;
  15579. }
  15580. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15581. {
  15582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15583. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15584. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15585. {
  15586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15587. }
  15588. else
  15589. {
  15590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15591. }
  15592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15593. isKnowKey = TRUE;
  15594. }
  15595. #if 1
  15596. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15597. {
  15598. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15600. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15601. {
  15602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15603. }
  15604. else
  15605. {
  15606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15607. }
  15608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15609. isKnowKey = TRUE;
  15610. }
  15611. #endif
  15612. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15613. {
  15614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15616. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15617. {
  15618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15619. }
  15620. else
  15621. {
  15622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15623. }
  15624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15625. isKnowKey = TRUE;
  15626. }
  15627. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15628. {
  15629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15630. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15631. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15632. {
  15633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15634. }
  15635. else
  15636. {
  15637. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15638. }
  15639. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15640. isKnowKey = TRUE;
  15641. }
  15642. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15643. {
  15644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15645. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15646. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15647. {
  15648. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15649. }
  15650. else
  15651. {
  15652. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15653. }
  15654. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15655. isKnowKey = TRUE;
  15656. }
  15657. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15658. {
  15659. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15660. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15661. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15662. {
  15663. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15664. }
  15665. else
  15666. {
  15667. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15668. }
  15669. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15670. isKnowKey = TRUE;
  15671. }
  15672. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15673. {
  15674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15675. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15676. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15677. {
  15678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15679. }
  15680. else
  15681. {
  15682. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15683. }
  15684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15685. isKnowKey = TRUE;
  15686. }
  15687. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15688. {
  15689. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15690. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15691. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15692. {
  15693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15694. }
  15695. else
  15696. {
  15697. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15698. }
  15699. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15700. isKnowKey = TRUE;
  15701. }
  15702. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15703. {
  15704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15705. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15706. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15707. {
  15708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15709. }
  15710. else
  15711. {
  15712. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15713. }
  15714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15715. isKnowKey = TRUE;
  15716. }
  15717. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15718. {
  15719. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15720. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15721. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15722. {
  15723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15724. }
  15725. else
  15726. {
  15727. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15728. }
  15729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15730. isKnowKey = TRUE;
  15731. }
  15732. //=========================================================
  15733. if(!isEmpty && !isKnowKey)
  15734. {
  15735. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15736. strcpy(unknownkey[UnknownKeynum], keyReq);
  15737. UnknownKeynum = UnknownKeynum + 1;
  15738. }
  15739. }
  15740. void processUnkownKey(void)
  15741. {
  15742. DEBUG_INFO("processUnkownKey...\n");
  15743. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15744. for(int index=0; index < UnknownKeynum; index++)
  15745. {
  15746. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15747. {
  15748. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15749. }
  15750. }
  15751. }
  15752. int setKeyValue(char *key, char *value)
  15753. {
  15754. int isSuccess = NotSupported;
  15755. int check_ascii=0;
  15756. char str[501]={0};
  15757. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15758. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15759. {
  15760. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15761. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15762. {
  15763. strcpy(str, (const char*)value);
  15764. for(int i = 0; str[i]; i++){
  15765. str[i] = tolower(str[i]);
  15766. }
  15767. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15768. isSuccess = ConfigurationStatus_Accepted;
  15769. }
  15770. else
  15771. {
  15772. isSuccess = ConfigurationStatus_Rejected;
  15773. }
  15774. }
  15775. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15776. {
  15777. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15778. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15779. {
  15780. strcpy(str, (const char*)value);
  15781. for(int i = 0; str[i]; i++){
  15782. str[i] = tolower(str[i]);
  15783. }
  15784. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15785. isSuccess = ConfigurationStatus_Accepted;
  15786. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15787. }
  15788. else
  15789. {
  15790. isSuccess = ConfigurationStatus_Rejected;
  15791. }
  15792. }
  15793. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15794. {
  15795. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15796. {
  15797. strcpy(str, (const char*)value);
  15798. for(int i = 0; str[i]; i++)
  15799. {
  15800. str[i] = tolower(str[i]);
  15801. }
  15802. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15803. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15804. isSuccess = ConfigurationStatus_Accepted;
  15805. }
  15806. else
  15807. {
  15808. isSuccess = ConfigurationStatus_Rejected;
  15809. }
  15810. }
  15811. if(strcmp(key, "BlinkRepeat") == 0)
  15812. {
  15813. //Charger.BlinkRepeat = Integer.parseInt(value);
  15814. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15815. {
  15816. check_ascii = value[0];
  15817. if( (check_ascii < 48) || (check_ascii > 57) )
  15818. {
  15819. isSuccess = ConfigurationStatus_Rejected;
  15820. }
  15821. else
  15822. {
  15823. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15824. isSuccess = ConfigurationStatus_Accepted;
  15825. }
  15826. }
  15827. else
  15828. {
  15829. isSuccess = ConfigurationStatus_Rejected;
  15830. }
  15831. }
  15832. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15833. {
  15834. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15835. {
  15836. check_ascii = value[0];
  15837. if( (check_ascii < 48) || (check_ascii > 57) )
  15838. {
  15839. isSuccess = ConfigurationStatus_Rejected;
  15840. }
  15841. else
  15842. {
  15843. if((atoi(value) == 0) || (atoi(value) >= 5))
  15844. {
  15845. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15846. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15847. isSuccess = ConfigurationStatus_Accepted;
  15848. }
  15849. else
  15850. isSuccess = ConfigurationStatus_Rejected;
  15851. }
  15852. }
  15853. else
  15854. {
  15855. isSuccess = ConfigurationStatus_Rejected;
  15856. }
  15857. }
  15858. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15859. {
  15860. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15861. {
  15862. check_ascii = value[0];
  15863. if( (check_ascii < 48) || (check_ascii > 57) )
  15864. {
  15865. isSuccess = ConfigurationStatus_Rejected;
  15866. }
  15867. else
  15868. {
  15869. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15870. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15871. isSuccess = ConfigurationStatus_Accepted;
  15872. }
  15873. }
  15874. else
  15875. {
  15876. isSuccess = ConfigurationStatus_Rejected;
  15877. }
  15878. }
  15879. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15880. {
  15881. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15882. {
  15883. check_ascii = value[0];
  15884. if( (check_ascii < 48) || (check_ascii > 57) )
  15885. {
  15886. isSuccess = ConfigurationStatus_Rejected;
  15887. }
  15888. else
  15889. {
  15890. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15891. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15892. isSuccess = ConfigurationStatus_Accepted;
  15893. }
  15894. }
  15895. else
  15896. {
  15897. isSuccess = ConfigurationStatus_Rejected;
  15898. }
  15899. }
  15900. if(strcmp(key, "HeartbeatInterval") == 0)
  15901. {
  15902. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15903. {
  15904. check_ascii = value[0];
  15905. if( (check_ascii < 48) || (check_ascii > 57) )
  15906. {
  15907. isSuccess = ConfigurationStatus_Rejected;
  15908. }
  15909. else
  15910. {
  15911. if((atoi(value) == 0) || (atoi(value) >= 10))
  15912. {
  15913. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15914. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15915. HeartBeatWaitTime = atoi(value);
  15916. isSuccess = ConfigurationStatus_Accepted;
  15917. }
  15918. else
  15919. {
  15920. isSuccess = ConfigurationStatus_Rejected;
  15921. }
  15922. }
  15923. }
  15924. else
  15925. {
  15926. isSuccess = ConfigurationStatus_Rejected;
  15927. }
  15928. }
  15929. if(strcmp(key, "LightIntensity") == 0)
  15930. {
  15931. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15932. {
  15933. check_ascii = value[0];
  15934. if( (check_ascii < 48) || (check_ascii > 57) )
  15935. {
  15936. isSuccess = ConfigurationStatus_Rejected;
  15937. }
  15938. else
  15939. {
  15940. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15941. isSuccess = ConfigurationStatus_Accepted;
  15942. }
  15943. }
  15944. else
  15945. {
  15946. isSuccess = ConfigurationStatus_Rejected;
  15947. }
  15948. }
  15949. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15950. {
  15951. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15952. {
  15953. strcpy(str, (const char*)value);
  15954. for(int i = 0; str[i]; i++)
  15955. {
  15956. str[i] = tolower(str[i]);
  15957. }
  15958. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15959. isSuccess = ConfigurationStatus_Accepted;
  15960. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15961. }
  15962. else
  15963. {
  15964. isSuccess = ConfigurationStatus_Rejected;
  15965. }
  15966. }
  15967. if(strcmp(key, "LocalPreAuthorize") == 0)
  15968. {
  15969. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15970. {
  15971. strcpy(str, (const char*)value);
  15972. for(int i = 0; str[i]; i++)
  15973. {
  15974. str[i] = tolower(str[i]);
  15975. }
  15976. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15977. isSuccess = ConfigurationStatus_Accepted;
  15978. }
  15979. else
  15980. {
  15981. isSuccess = ConfigurationStatus_Rejected;
  15982. }
  15983. }
  15984. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15985. {
  15986. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15987. {
  15988. check_ascii = value[0];
  15989. if( (check_ascii < 48) || (check_ascii > 57) )
  15990. {
  15991. isSuccess = ConfigurationStatus_Rejected;
  15992. }
  15993. else
  15994. {
  15995. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15996. isSuccess = ConfigurationStatus_Accepted;
  15997. }
  15998. }
  15999. else
  16000. {
  16001. isSuccess = ConfigurationStatus_Rejected;
  16002. }
  16003. }
  16004. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16005. {
  16006. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16007. {
  16008. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16009. isSuccess = ConfigurationStatus_Accepted;
  16010. }
  16011. else
  16012. {
  16013. isSuccess = ConfigurationStatus_Rejected;
  16014. }
  16015. }
  16016. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16017. {
  16018. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16019. {
  16020. check_ascii = value[0];
  16021. if( (check_ascii < 48) || (check_ascii > 57) )
  16022. {
  16023. isSuccess = ConfigurationStatus_Rejected;
  16024. }
  16025. else
  16026. {
  16027. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16028. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16029. isSuccess = ConfigurationStatus_Accepted;
  16030. }
  16031. }
  16032. else
  16033. {
  16034. isSuccess = ConfigurationStatus_Rejected;
  16035. }
  16036. }
  16037. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16038. {
  16039. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16040. {
  16041. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16042. isSuccess = ConfigurationStatus_Accepted;
  16043. }
  16044. else
  16045. {
  16046. isSuccess = ConfigurationStatus_Rejected;
  16047. }
  16048. }
  16049. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16050. {
  16051. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16052. {
  16053. check_ascii = value[0];
  16054. if( (check_ascii < 48) || (check_ascii > 57) )
  16055. {
  16056. isSuccess = ConfigurationStatus_Rejected;
  16057. }
  16058. else
  16059. {
  16060. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16061. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16062. isSuccess = ConfigurationStatus_Accepted;
  16063. }
  16064. }
  16065. else
  16066. {
  16067. isSuccess = ConfigurationStatus_Rejected;
  16068. }
  16069. }
  16070. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16071. {
  16072. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16073. {
  16074. check_ascii = value[0];
  16075. if( (check_ascii < 48) || (check_ascii > 57) )
  16076. {
  16077. isSuccess = ConfigurationStatus_Rejected;
  16078. }
  16079. else
  16080. {
  16081. if((atoi(value) == 0) || (atoi(value) >= 3))
  16082. {
  16083. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16084. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16085. isSuccess = ConfigurationStatus_Accepted;
  16086. }
  16087. else
  16088. {
  16089. isSuccess = ConfigurationStatus_Rejected;
  16090. }
  16091. }
  16092. }
  16093. else
  16094. {
  16095. isSuccess = ConfigurationStatus_Rejected;
  16096. }
  16097. }
  16098. if(strcmp(key, "MinimumStatusDuration") == 0)
  16099. {
  16100. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16101. {
  16102. check_ascii = value[0];
  16103. if( (check_ascii < 48) || (check_ascii > 57) )
  16104. {
  16105. isSuccess = ConfigurationStatus_Rejected;
  16106. }
  16107. else
  16108. {
  16109. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16110. {
  16111. isSuccess = ConfigurationStatus_Rejected;
  16112. }
  16113. else
  16114. {
  16115. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16116. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16117. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16118. isSuccess = ConfigurationStatus_Accepted;
  16119. }
  16120. }
  16121. }
  16122. else
  16123. {
  16124. isSuccess = ConfigurationStatus_Rejected;
  16125. }
  16126. }
  16127. if(strcmp(key, "NumberOfConnectors") == 0)
  16128. {
  16129. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16130. {
  16131. check_ascii = value[0];
  16132. if( (check_ascii < 48) || (check_ascii > 57) )
  16133. {
  16134. isSuccess = ConfigurationStatus_Rejected;
  16135. }
  16136. else
  16137. {
  16138. //Charger.ResetRetries = Integer.parseInt(value);
  16139. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16140. isSuccess = ConfigurationStatus_Accepted;
  16141. }
  16142. }
  16143. else
  16144. {
  16145. isSuccess = ConfigurationStatus_Rejected;
  16146. }
  16147. }
  16148. if(strcmp(key, "ResetRetries") == 0)
  16149. {
  16150. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16151. {
  16152. check_ascii = value[0];
  16153. if( (check_ascii < 48) || (check_ascii > 57) )
  16154. {
  16155. isSuccess = ConfigurationStatus_Rejected;
  16156. }
  16157. else
  16158. {
  16159. //Charger.ResetRetries = Integer.parseInt(value);
  16160. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16161. isSuccess = ConfigurationStatus_Accepted;
  16162. }
  16163. }
  16164. else
  16165. {
  16166. isSuccess = ConfigurationStatus_Rejected;
  16167. }
  16168. }
  16169. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16170. {
  16171. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16172. {
  16173. strcpy(str, (const char*)value);
  16174. for(int i = 0; str[i]; i++)
  16175. {
  16176. str[i] = tolower(str[i]);
  16177. }
  16178. if(strcmp(str, "notapplicable")== 0)
  16179. {
  16180. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16181. isSuccess = ConfigurationStatus_Accepted;
  16182. }
  16183. else if(strcmp(str, "unknown")== 0)
  16184. {
  16185. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16186. isSuccess = ConfigurationStatus_Accepted;
  16187. }
  16188. else if(strcmp(str, "rst")== 0)
  16189. {
  16190. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16191. isSuccess = ConfigurationStatus_Accepted;
  16192. }
  16193. else if(strcmp(str, "rts")== 0)
  16194. {
  16195. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16196. isSuccess = ConfigurationStatus_Accepted;
  16197. }
  16198. else if(strcmp(str, "srt")== 0)
  16199. {
  16200. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16201. isSuccess = ConfigurationStatus_Accepted;
  16202. }
  16203. else if(strcmp(str, "str")== 0)
  16204. {
  16205. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16206. isSuccess = ConfigurationStatus_Accepted;
  16207. }
  16208. else if(strcmp(str, "trs")== 0)
  16209. {
  16210. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16211. isSuccess = ConfigurationStatus_Accepted;
  16212. }
  16213. else if(strcmp(str, "tsr")== 0)
  16214. {
  16215. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16216. isSuccess = ConfigurationStatus_Accepted;
  16217. }
  16218. else
  16219. {
  16220. isSuccess = ConfigurationStatus_Rejected;
  16221. }
  16222. }
  16223. else
  16224. {
  16225. isSuccess = ConfigurationStatus_Rejected;
  16226. }
  16227. }
  16228. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16229. {
  16230. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16231. {
  16232. check_ascii = value[0];
  16233. if( (check_ascii < 48) || (check_ascii > 57) )
  16234. {
  16235. isSuccess = ConfigurationStatus_Rejected;
  16236. }
  16237. else
  16238. {
  16239. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16240. isSuccess = ConfigurationStatus_Accepted;
  16241. }
  16242. }
  16243. else
  16244. {
  16245. isSuccess = ConfigurationStatus_Rejected;
  16246. }
  16247. }
  16248. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16249. {
  16250. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16251. {
  16252. strcpy(str, (const char*)value);
  16253. for(int i = 0; str[i]; i++)
  16254. {
  16255. str[i] = tolower(str[i]);
  16256. }
  16257. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16258. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16259. isSuccess = ConfigurationStatus_Accepted;
  16260. }
  16261. else
  16262. {
  16263. isSuccess = ConfigurationStatus_Rejected;
  16264. }
  16265. }
  16266. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16267. {
  16268. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16269. {
  16270. strcpy(str, (const char*)value);
  16271. for(int i = 0; str[i]; i++)
  16272. {
  16273. str[i] = tolower(str[i]);
  16274. }
  16275. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16276. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16277. isSuccess = ConfigurationStatus_Accepted;
  16278. }
  16279. else
  16280. {
  16281. isSuccess = ConfigurationStatus_Rejected;
  16282. }
  16283. }
  16284. if(strcmp(key, "StopTxnAlignedData") == 0)
  16285. {
  16286. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16287. {
  16288. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16289. isSuccess = ConfigurationStatus_Accepted;
  16290. }
  16291. else
  16292. {
  16293. isSuccess = ConfigurationStatus_Rejected;
  16294. }
  16295. }
  16296. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16297. {
  16298. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16299. {
  16300. check_ascii = value[0];
  16301. if( (check_ascii < 48) || (check_ascii > 57) )
  16302. {
  16303. isSuccess = ConfigurationStatus_Rejected;
  16304. }
  16305. else
  16306. {
  16307. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16308. isSuccess = ConfigurationStatus_Accepted;
  16309. }
  16310. }
  16311. else
  16312. {
  16313. isSuccess = ConfigurationStatus_Rejected;
  16314. }
  16315. }
  16316. if(strcmp(key, "StopTxnSampledData") == 0)
  16317. {
  16318. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16319. {
  16320. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16321. isSuccess = ConfigurationStatus_Accepted;
  16322. }
  16323. else
  16324. {
  16325. isSuccess = ConfigurationStatus_Rejected;
  16326. }
  16327. }
  16328. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16329. {
  16330. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16331. {
  16332. check_ascii = value[0];
  16333. if( (check_ascii < 48) || (check_ascii > 57) )
  16334. {
  16335. isSuccess = ConfigurationStatus_Rejected;
  16336. }
  16337. else
  16338. {
  16339. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16340. isSuccess = ConfigurationStatus_Accepted;
  16341. }
  16342. }
  16343. else
  16344. {
  16345. isSuccess = ConfigurationStatus_Rejected;
  16346. }
  16347. }
  16348. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16349. {
  16350. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16351. {
  16352. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16353. isSuccess = ConfigurationStatus_Accepted;
  16354. }
  16355. else
  16356. {
  16357. isSuccess = ConfigurationStatus_Rejected;
  16358. }
  16359. }
  16360. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16361. {
  16362. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16363. {
  16364. check_ascii = value[0];
  16365. if( (check_ascii < 48) || (check_ascii > 57) )
  16366. {
  16367. isSuccess = ConfigurationStatus_Rejected;
  16368. }
  16369. else
  16370. {
  16371. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16372. isSuccess = ConfigurationStatus_Accepted;
  16373. }
  16374. }
  16375. else
  16376. {
  16377. isSuccess = ConfigurationStatus_Rejected;
  16378. }
  16379. }
  16380. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16381. {
  16382. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16383. {
  16384. check_ascii = value[0];
  16385. if( (check_ascii < 48) || (check_ascii > 57) )
  16386. {
  16387. isSuccess = ConfigurationStatus_Rejected;
  16388. }
  16389. else
  16390. {
  16391. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16392. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16393. TransactionMessageAttemptsValue = atoi(value);
  16394. isSuccess = ConfigurationStatus_Accepted;
  16395. }
  16396. }
  16397. else
  16398. {
  16399. isSuccess = ConfigurationStatus_Rejected;
  16400. }
  16401. }
  16402. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16403. {
  16404. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16405. {
  16406. check_ascii = value[0];
  16407. if( (check_ascii < 48) || (check_ascii > 57) )
  16408. {
  16409. isSuccess = ConfigurationStatus_Rejected;
  16410. }
  16411. else
  16412. {
  16413. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16414. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16415. TransactionMessageRetryIntervalValue = atoi(value);
  16416. isSuccess = ConfigurationStatus_Accepted;
  16417. }
  16418. }
  16419. else
  16420. {
  16421. isSuccess = ConfigurationStatus_Rejected;
  16422. }
  16423. }
  16424. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16425. {
  16426. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16427. {
  16428. strcpy(str, (const char*)value);
  16429. for(int i = 0; str[i]; i++)
  16430. {
  16431. str[i] = tolower(str[i]);
  16432. }
  16433. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16434. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16435. isSuccess = ConfigurationStatus_Accepted;
  16436. }
  16437. else
  16438. {
  16439. isSuccess = ConfigurationStatus_Rejected;
  16440. }
  16441. }
  16442. if(strcmp(key, "WebSocketPingInterval") == 0)
  16443. {
  16444. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16445. {
  16446. check_ascii = value[0];
  16447. if( (check_ascii < 48) || (check_ascii > 57) )
  16448. {
  16449. isSuccess = ConfigurationStatus_Rejected;
  16450. }
  16451. else
  16452. {
  16453. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16454. isSuccess = ConfigurationStatus_Accepted;
  16455. if((atoi(value) == 0) || (atoi(value) >= 10))
  16456. {
  16457. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16458. isSuccess = ConfigurationStatus_Accepted;
  16459. }
  16460. else
  16461. isSuccess = ConfigurationStatus_Rejected;
  16462. }
  16463. }
  16464. else
  16465. {
  16466. isSuccess = ConfigurationStatus_Rejected;
  16467. }
  16468. }
  16469. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16470. {
  16471. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16472. {
  16473. strcpy(str, (const char*)value);
  16474. for(int i = 0; str[i]; i++)
  16475. {
  16476. str[i] = tolower(str[i]);
  16477. }
  16478. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16479. isSuccess = ConfigurationStatus_Accepted;
  16480. }
  16481. else
  16482. {
  16483. isSuccess = ConfigurationStatus_Rejected;
  16484. }
  16485. }
  16486. if(strcmp(key, "AuthorizationKey") == 0)
  16487. {
  16488. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16489. {
  16490. strcpy(str, (const char*)value);
  16491. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16492. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16493. isSuccess = ConfigurationStatus_Accepted;
  16494. }
  16495. else
  16496. {
  16497. isSuccess = ConfigurationStatus_Rejected;
  16498. }
  16499. }
  16500. if(strcmp(key, "SecurityProfile") == 0)
  16501. {
  16502. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16503. {
  16504. check_ascii = value[0];
  16505. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16506. {
  16507. isSuccess = ConfigurationStatus_Rejected;
  16508. }
  16509. else if(check_ascii == 0x33)
  16510. {
  16511. isSuccess = NotSupported;
  16512. }
  16513. else
  16514. {
  16515. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16516. {
  16517. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16518. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16519. isSuccess = ConfigurationStatus_Accepted;
  16520. }
  16521. else
  16522. isSuccess = ConfigurationStatus_Rejected;
  16523. }
  16524. }
  16525. else
  16526. {
  16527. isSuccess = ConfigurationStatus_Rejected;
  16528. }
  16529. }
  16530. if(strcmp(key, "DefaultPrice") == 0)
  16531. {
  16532. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16533. {
  16534. strcpy(str, (const char*)value);
  16535. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16536. isSuccess = ConfigurationStatus_Accepted;
  16537. }
  16538. else
  16539. {
  16540. isSuccess = ConfigurationStatus_Rejected;
  16541. }
  16542. }
  16543. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16544. {
  16545. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16546. {
  16547. strcpy(str, (const char*)value);
  16548. for(int i = 0; str[i]; i++)
  16549. {
  16550. str[i] = tolower(str[i]);
  16551. }
  16552. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16553. isSuccess = ConfigurationStatus_Accepted;
  16554. }
  16555. else
  16556. {
  16557. isSuccess = ConfigurationStatus_Rejected;
  16558. }
  16559. }
  16560. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16561. {
  16562. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16563. {
  16564. strcpy(str, (const char*)value);
  16565. for(int i = 0; str[i]; i++)
  16566. {
  16567. str[i] = tolower(str[i]);
  16568. }
  16569. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16570. isSuccess = ConfigurationStatus_Accepted;
  16571. }
  16572. else
  16573. {
  16574. isSuccess = ConfigurationStatus_Rejected;
  16575. }
  16576. }
  16577. if(strcmp(key, "SystemUptimeSec") == 0)
  16578. {
  16579. isSuccess = NotSupported;
  16580. }
  16581. if(strcmp(key, "FreeVend") == 0)
  16582. {
  16583. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16584. {
  16585. strcpy(str, (const char*)value);
  16586. for(int i = 0; str[i]; i++)
  16587. {
  16588. str[i] = tolower(str[i]);
  16589. }
  16590. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16591. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16592. isSuccess = ConfigurationStatus_Accepted;
  16593. }
  16594. else
  16595. {
  16596. isSuccess = ConfigurationStatus_Rejected;
  16597. }
  16598. }
  16599. if(strcmp(key, "FreeVendIdtag") == 0)
  16600. {
  16601. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16602. {
  16603. strcpy(str, (const char*)value);
  16604. if(strlen(str) <= 20)
  16605. {
  16606. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16607. isSuccess = ConfigurationStatus_Accepted;
  16608. }
  16609. else
  16610. {
  16611. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16612. isSuccess = ConfigurationStatus_Rejected;
  16613. }
  16614. }
  16615. else
  16616. {
  16617. isSuccess = ConfigurationStatus_Rejected;
  16618. }
  16619. }
  16620. if(strcmp(key, "OcppServer") == 0)
  16621. {
  16622. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16623. {
  16624. strcpy(str, (const char*)value);
  16625. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16626. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16627. isSuccess = ConfigurationStatus_Accepted;
  16628. }
  16629. else
  16630. {
  16631. isSuccess = ConfigurationStatus_Rejected;
  16632. }
  16633. }
  16634. if(strcmp(key, "MaintainServer") == 0)
  16635. {
  16636. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16637. {
  16638. strcpy(str, (const char*)value);
  16639. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16640. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16641. isSuccess = ConfigurationStatus_Accepted;
  16642. }
  16643. else
  16644. {
  16645. isSuccess = ConfigurationStatus_Rejected;
  16646. }
  16647. }
  16648. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16649. {
  16650. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16651. {
  16652. strcpy(str, (const char*)value);
  16653. for(int i = 0; str[i]; i++)
  16654. {
  16655. str[i] = tolower(str[i]);
  16656. }
  16657. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16658. isSuccess = ConfigurationStatus_Accepted;
  16659. }
  16660. else
  16661. {
  16662. isSuccess = ConfigurationStatus_Rejected;
  16663. }
  16664. }
  16665. if(strcmp(key, "StatusNotificationInterval") == 0)
  16666. {
  16667. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16668. {
  16669. check_ascii = value[0];
  16670. if( (check_ascii < 48) || (check_ascii > 57) )
  16671. {
  16672. isSuccess = ConfigurationStatus_Rejected;
  16673. }
  16674. else
  16675. {
  16676. if((atoi(value) == 0) || (atoi(value) >= 10))
  16677. {
  16678. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16679. isSuccess = ConfigurationStatus_Accepted;
  16680. }
  16681. else
  16682. isSuccess = ConfigurationStatus_Rejected;
  16683. }
  16684. }
  16685. else
  16686. {
  16687. isSuccess = ConfigurationStatus_Rejected;
  16688. }
  16689. }
  16690. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  16691. {
  16692. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16693. {
  16694. check_ascii = value[0];
  16695. if( (check_ascii < 48) || (check_ascii > 57) )
  16696. {
  16697. isSuccess = ConfigurationStatus_Rejected;
  16698. }
  16699. else
  16700. {
  16701. if(atoi(value) >= 0)
  16702. {
  16703. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value) );
  16704. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  16705. isSuccess = ConfigurationStatus_Accepted;
  16706. }
  16707. else
  16708. isSuccess = ConfigurationStatus_Rejected;
  16709. }
  16710. }
  16711. else
  16712. {
  16713. isSuccess = ConfigurationStatus_Rejected;
  16714. }
  16715. }
  16716. if(strcmp(key, "PowerSharingServerIP") == 0)
  16717. {
  16718. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16719. {
  16720. strcpy(str, (const char*)value);
  16721. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  16722. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  16723. isSuccess = ConfigurationStatus_Accepted;
  16724. }
  16725. else
  16726. {
  16727. isSuccess = ConfigurationStatus_Rejected;
  16728. }
  16729. }
  16730. if(strcmp(key, "EVCCID_PREFIX") == 0)
  16731. {
  16732. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16733. {
  16734. strcpy(str, (const char*)value);
  16735. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  16736. isSuccess = ConfigurationStatus_Accepted;
  16737. }
  16738. else
  16739. {
  16740. isSuccess = ConfigurationStatus_Rejected;
  16741. }
  16742. }
  16743. #if 0
  16744. //For OCPP Test Case
  16745. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16746. {
  16747. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16748. {
  16749. strcpy(str, (const char*)value);
  16750. for(int i = 0; str[i]; i++)
  16751. {
  16752. str[i] = tolower(str[i]);
  16753. }
  16754. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16755. isSuccess = ConfigurationStatus_Accepted;
  16756. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16757. }
  16758. else
  16759. {
  16760. isSuccess = ConfigurationStatus_Rejected;
  16761. }
  16762. }
  16763. #endif
  16764. #if 1
  16765. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16766. {
  16767. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16768. {
  16769. strcpy(str, (const char*)value);
  16770. for(int i = 0; str[i]; i++)
  16771. {
  16772. str[i] = tolower(str[i]);
  16773. }
  16774. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16775. isSuccess = ConfigurationStatus_Accepted;
  16776. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16777. }
  16778. else
  16779. {
  16780. isSuccess = ConfigurationStatus_Rejected;
  16781. }
  16782. }
  16783. #endif
  16784. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16785. {
  16786. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16787. {
  16788. check_ascii = value[0];
  16789. if( (check_ascii < 48) || (check_ascii > 57) )
  16790. {
  16791. isSuccess = ConfigurationStatus_Rejected;
  16792. }
  16793. else
  16794. {
  16795. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16796. isSuccess = ConfigurationStatus_Accepted;
  16797. }
  16798. }
  16799. else
  16800. {
  16801. isSuccess = ConfigurationStatus_Rejected;
  16802. }
  16803. }
  16804. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16805. {
  16806. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16807. {
  16808. check_ascii = value[0];
  16809. if( (check_ascii < 48) || (check_ascii > 57) )
  16810. {
  16811. isSuccess = ConfigurationStatus_Rejected;
  16812. }
  16813. else
  16814. {
  16815. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16816. isSuccess = ConfigurationStatus_Accepted;
  16817. }
  16818. }
  16819. else
  16820. {
  16821. isSuccess = ConfigurationStatus_Rejected;
  16822. }
  16823. }
  16824. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16825. {
  16826. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16827. {
  16828. strcpy(str, (const char*)value);
  16829. for(int i = 0; str[i]; i++)
  16830. {
  16831. str[i] = tolower(str[i]);
  16832. }
  16833. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16834. isSuccess = ConfigurationStatus_Accepted;
  16835. }
  16836. else
  16837. {
  16838. isSuccess = ConfigurationStatus_Rejected;
  16839. }
  16840. }
  16841. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16842. {
  16843. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16844. {
  16845. check_ascii = value[0];
  16846. if( (check_ascii < 48) || (check_ascii > 57) )
  16847. {
  16848. isSuccess = ConfigurationStatus_Rejected;
  16849. }
  16850. else
  16851. {
  16852. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16853. isSuccess = ConfigurationStatus_Accepted;
  16854. }
  16855. }
  16856. else
  16857. {
  16858. isSuccess = ConfigurationStatus_Rejected;
  16859. }
  16860. }
  16861. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16862. {
  16863. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16864. {
  16865. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16866. isSuccess = ConfigurationStatus_Accepted;
  16867. }
  16868. else
  16869. {
  16870. isSuccess = ConfigurationStatus_Rejected;
  16871. }
  16872. }
  16873. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16874. {
  16875. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16876. {
  16877. check_ascii = value[0];
  16878. if( (check_ascii < 48) || (check_ascii > 57) )
  16879. {
  16880. isSuccess = ConfigurationStatus_Rejected;
  16881. }
  16882. else
  16883. {
  16884. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16885. isSuccess = ConfigurationStatus_Accepted;
  16886. }
  16887. }
  16888. else
  16889. {
  16890. isSuccess = ConfigurationStatus_Rejected;
  16891. }
  16892. }
  16893. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16894. {
  16895. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16896. {
  16897. strcpy(str, (const char*)value);
  16898. for(int i = 0; str[i]; i++)
  16899. {
  16900. str[i] = tolower(str[i]);
  16901. }
  16902. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16903. isSuccess = ConfigurationStatus_Accepted;
  16904. }
  16905. else
  16906. {
  16907. isSuccess = ConfigurationStatus_Rejected;
  16908. }
  16909. }
  16910. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16911. {
  16912. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16913. {
  16914. check_ascii = value[0];
  16915. if( (check_ascii < 48) || (check_ascii > 57) )
  16916. {
  16917. isSuccess = ConfigurationStatus_Rejected;
  16918. }
  16919. else
  16920. {
  16921. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16922. isSuccess = ConfigurationStatus_Accepted;
  16923. }
  16924. }
  16925. else
  16926. {
  16927. isSuccess = ConfigurationStatus_Rejected;
  16928. }
  16929. }
  16930. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16931. return isSuccess;
  16932. }
  16933. int TransactionMessageAttemptsGet(void)
  16934. {
  16935. return TransactionMessageAttemptsValue;
  16936. }
  16937. int FirstHeartBeatResponse(void)
  16938. {
  16939. return FirstHeartBeat;
  16940. }
  16941. int TransactionMessageRetryIntervalGet(void)
  16942. {
  16943. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16944. }
  16945. int ReadHttpStatus(int sock)
  16946. {
  16947. //char c;
  16948. char buff[1024]="",*ptr=buff+1;
  16949. int bytes_received, status;
  16950. DEBUG_INFO("Begin Response ..\n");
  16951. while((bytes_received = recv(sock, ptr, 1, 0))){
  16952. if(bytes_received==-1){
  16953. perror("ReadHttpStatus");
  16954. exit(1);
  16955. }
  16956. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16957. ptr++;
  16958. }
  16959. *ptr=0;
  16960. ptr=buff+1;
  16961. sscanf(ptr,"%*s %d ", &status);
  16962. DEBUG_INFO("%s\n",ptr);
  16963. DEBUG_INFO("status=%d\n",status);
  16964. DEBUG_INFO("End Response ..\n");
  16965. return (bytes_received>0)?status:0;
  16966. }
  16967. //the only filed that it parsed is 'Content-Length'
  16968. int ParseHeader(int sock)
  16969. {
  16970. //char c;
  16971. char buff[1024]="",*ptr=buff+4;
  16972. int bytes_received;
  16973. DEBUG_INFO("Begin HEADER ..\n");
  16974. while((bytes_received = recv(sock, ptr, 1, 0))){
  16975. if(bytes_received==-1){
  16976. perror("Parse Header");
  16977. exit(1);
  16978. }
  16979. if(
  16980. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16981. (ptr[-1]=='\r') && (*ptr=='\n' )
  16982. ) break;
  16983. ptr++;
  16984. }
  16985. *ptr=0;
  16986. ptr=buff+4;
  16987. //printf("%s",ptr);
  16988. if(bytes_received){
  16989. ptr=strstr(ptr,"Content-Length:");
  16990. if(ptr){
  16991. sscanf(ptr,"%*s %d",&bytes_received);
  16992. }else
  16993. bytes_received=-1; //unknown size
  16994. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16995. }
  16996. DEBUG_INFO("End HEADER ..\n");
  16997. return bytes_received ;
  16998. }
  16999. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17000. {
  17001. int result = TRUE;
  17002. char rmFileCmd[100]={0};
  17003. char FilePath[100]={0};
  17004. char ftpbuf[200];
  17005. int systemresult;
  17006. sprintf(FilePath,"/mnt/%s",filename);
  17007. system("ping 8.8.8.8 &");
  17008. if((access(FilePath,F_OK))!=-1)
  17009. {
  17010. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17011. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17012. system(rmFileCmd);
  17013. }
  17014. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17015. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17016. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17017. systemresult = system(ftpbuf);
  17018. if(systemresult != 0)
  17019. {
  17020. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17021. result = FALSE;
  17022. }
  17023. system("pkill ping");
  17024. return result;
  17025. }
  17026. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17027. {
  17028. int result = TRUE;
  17029. char rmFileCmd[100]={0};
  17030. char FilePath[100]={0};
  17031. char ftpbuf[200];
  17032. int systemresult;
  17033. sprintf(FilePath,"/mnt/%s",filename);
  17034. system("ping 8.8.8.8 &");
  17035. if((access(FilePath,F_OK))!=-1)
  17036. {
  17037. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17038. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17039. system(rmFileCmd);
  17040. }
  17041. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17042. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17043. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17044. systemresult = system(ftpbuf);
  17045. if(systemresult != 0)
  17046. {
  17047. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17048. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17049. systemresult = system(ftpbuf);
  17050. if(systemresult != 0)
  17051. {
  17052. DEBUG_WARN("FTP download fail!\n");
  17053. result = FALSE;
  17054. }
  17055. }
  17056. system("pkill ping");
  17057. return result;
  17058. }
  17059. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17060. {
  17061. char rmFileCmd[100]={0};
  17062. char FilePath[100]={0};
  17063. char buf[512];
  17064. int systemresult = 0;
  17065. //DEBUG_INFO("filename=%s\n",filename);
  17066. //DEBUG_INFO("url=%s\n",url);
  17067. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17068. if((access(FilePath,F_OK))!=-1)
  17069. {
  17070. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17071. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17072. system(rmFileCmd);
  17073. }
  17074. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17075. if(fp == NULL)
  17076. {
  17077. DEBUG_INFO("log is NULL\n");
  17078. return FALSE;
  17079. }
  17080. else
  17081. {
  17082. fprintf(fp, "%s\n", url);
  17083. fprintf(fp, "%s\n", filename);
  17084. fclose(fp);
  17085. }
  17086. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17087. if(phpFP == NULL)
  17088. {
  17089. DEBUG_INFO("PHP upload fail.\n");
  17090. return FALSE;
  17091. }
  17092. else
  17093. {
  17094. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17095. {
  17096. if(strstr(buf, "result") != NULL)
  17097. {
  17098. sscanf(buf, "result: %d", &systemresult);
  17099. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17100. }
  17101. }
  17102. pclose(phpFP);
  17103. }
  17104. if(systemresult != 1)
  17105. {
  17106. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17107. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17108. if(phpFP == NULL)
  17109. {
  17110. DEBUG_WARN("PHP PUT upload fail.\n");
  17111. return FALSE;
  17112. }
  17113. else
  17114. {
  17115. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17116. {
  17117. if(strstr(buf, "result") != NULL)
  17118. {
  17119. sscanf(buf, "result: %d", &systemresult);
  17120. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17121. }
  17122. }
  17123. pclose(phpFP);
  17124. }
  17125. }
  17126. if(systemresult != 1)
  17127. {
  17128. DEBUG_WARN("PHP PUT upload fail.\n");
  17129. return FALSE;
  17130. }
  17131. return TRUE;
  17132. }
  17133. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17134. {
  17135. int result = FALSE;
  17136. char ftpbuf[200];
  17137. int systemresult;
  17138. /*
  17139. // Domaind name transfer to IP address
  17140. struct hostent* server;
  17141. char *IPbuffer;
  17142. server = gethostbyname(location);
  17143. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17144. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17145. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17146. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17147. systemresult = system(ftpbuf);
  17148. if(systemresult != 0)
  17149. {
  17150. DEBUG_INFO("ftpput error!\n");
  17151. }
  17152. else
  17153. {
  17154. result = TRUE;
  17155. DEBUG_INFO("ftpput OK!\n");
  17156. }
  17157. return result;
  17158. }
  17159. int GetOcppServerURL()
  17160. {
  17161. int result = FALSE;
  17162. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17163. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17164. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17165. struct yuarel url;
  17166. char urlStr[512];
  17167. // OCPPPH only
  17168. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  17169. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  17170. {
  17171. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  17172. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17173. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17174. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  17175. if(yuarel_parse(&url, urlStr) != -1)
  17176. {
  17177. sprintf(OcppProtocol, "%s", url.scheme);
  17178. sprintf(OcppHost, "%s", url.host);
  17179. if(url.path == NULL)
  17180. OcppTempPath[0] = '\0';
  17181. else
  17182. sprintf(OcppTempPath, "%s", url.path);
  17183. if(url.port == 0)
  17184. {
  17185. if(strcmp(OcppProtocol, "wss") == 0)
  17186. OcppPort = 443;
  17187. else
  17188. OcppPort = 80;
  17189. }
  17190. else
  17191. OcppPort = url.port;
  17192. result = TRUE;
  17193. }
  17194. }
  17195. else
  17196. {
  17197. strcpy(OcppHost,"");
  17198. }
  17199. return result;
  17200. }
  17201. int GetOcppPath()
  17202. {
  17203. int result = FALSE;
  17204. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  17205. {
  17206. if(OcppTempPath == NULL)
  17207. {
  17208. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  17209. }
  17210. else
  17211. {
  17212. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  17213. }
  17214. result = TRUE;
  17215. goto End;
  17216. }
  17217. else
  17218. {
  17219. strcpy(OcppPath,"");
  17220. }
  17221. End:
  17222. return result;
  17223. }
  17224. int GetOcppPort()
  17225. {
  17226. return OcppPort;
  17227. }
  17228. int GetOcppConnStatus(void)
  17229. {
  17230. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17231. }
  17232. void SetOcppConnStatus(uint8_t status)
  17233. {
  17234. ShmOCPP16DataPH->OcppConnStatus = status;
  17235. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17236. }
  17237. int GetHeartBeatWithNOResponse(void)
  17238. {
  17239. return HeartBeatWithNOResponse;
  17240. }
  17241. void SetHeartBeatWithNOResponse(void)
  17242. {
  17243. HeartBeatWithNOResponse = 0;
  17244. }
  17245. void GetStartTransactionIdTag(int gun_index)
  17246. {
  17247. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17248. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17249. }
  17250. int GetStartTransactionId(int gun_index)
  17251. {
  17252. return ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17253. }
  17254. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17255. {
  17256. char ch;
  17257. FILE *fptr1;
  17258. int temptransactionId;
  17259. char str[100]={0};
  17260. temptransactionId = 0;
  17261. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17262. {
  17263. DEBUG_INFO("IdTag is empty.\n");
  17264. return temptransactionId;
  17265. }
  17266. /*------ Read the file ----------------*/
  17267. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17268. if (!fptr1)
  17269. {
  17270. DEBUG_INFO("QueueTransactionId file open error.\n");
  17271. //printf(" File not found or unable to open the input file!!\n");
  17272. return temptransactionId;
  17273. }
  17274. ch=fgetc(fptr1);
  17275. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17276. rewind(fptr1);
  17277. if(ch!=EOF)
  17278. {
  17279. // printf("%c",ch);
  17280. while (fgets(str, 100, fptr1) != NULL)
  17281. {
  17282. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17283. if(str[0]=='\0')
  17284. {
  17285. break;
  17286. }
  17287. char *revbuf[8] = {0}; // Variable store string split
  17288. int num = 0;// Quantity after string split
  17289. DEBUG_INFO("Transaction queue data= %s\n", str);
  17290. splitstring(str,",",revbuf,&num); // String split
  17291. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17292. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17293. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17294. DEBUG_INFO("------------------------------\n");
  17295. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17296. {
  17297. if(isStopTransaction)
  17298. {
  17299. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17300. {
  17301. temptransactionId = atoi(revbuf[2]);
  17302. //break;
  17303. }
  17304. }
  17305. else
  17306. {
  17307. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17308. {
  17309. temptransactionId = atoi(revbuf[2]);
  17310. //break;
  17311. }
  17312. }
  17313. }
  17314. }
  17315. }
  17316. else
  17317. DEBUG_INFO("EOF\n");
  17318. fclose(fptr1);
  17319. /*------- End of reading ---------------*/
  17320. return temptransactionId;
  17321. }
  17322. void SetTransactionIdZero(int transactionId)
  17323. {
  17324. char ch;
  17325. FILE *fptr1, *fptr2;
  17326. int temptransactionId = 0;
  17327. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17328. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17329. if (!fptr1)
  17330. {
  17331. //printf(" File not found or unable to open the input file!!\n");
  17332. return ;
  17333. }
  17334. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17335. if (!fptr2)
  17336. {
  17337. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17338. fclose(fptr1);
  17339. return ;
  17340. }
  17341. ch=fgetc(fptr1);
  17342. rewind(fptr1);
  17343. if(ch!=EOF)
  17344. {
  17345. // copy all contents to the temporary file except the specific line
  17346. while (fgets(str, 100, fptr1) != NULL)
  17347. {
  17348. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17349. if(str[0]=='\0')
  17350. {
  17351. break;
  17352. }
  17353. char *revbuf[8] = {0};
  17354. int num = 0;
  17355. strcpy(strtemp, str);
  17356. splitstring(str,",",revbuf,&num);
  17357. if(revbuf[2][0] != '\0')
  17358. {
  17359. temptransactionId = atoi(revbuf[2]);
  17360. if(transactionId != temptransactionId)
  17361. {
  17362. fprintf(fptr2, "%s\n", strtemp);
  17363. }
  17364. }
  17365. }
  17366. }
  17367. fclose(fptr1);
  17368. fclose(fptr2);
  17369. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17370. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17371. /*------ Read the file ----------------*/
  17372. }
  17373. int InternetDisconnect(void)
  17374. {
  17375. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17376. }
  17377. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17378. void storeTempStopTransaction(int gun_index)
  17379. {
  17380. char guid[37]={0};
  17381. int tempIndex = 0;
  17382. char TempStopTransaction[256];
  17383. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17384. DEBUG_INFO("storeTempStopTransaction...\n");
  17385. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17386. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17387. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17388. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17389. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17390. {
  17391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17392. {
  17393. tempIndex = ((gun_index==2) ? 1: 0);
  17394. }
  17395. else
  17396. {
  17397. tempIndex = gun_index;
  17398. }
  17399. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17400. {
  17401. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17402. {
  17403. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17404. }
  17405. }// END OF CHAdeMO_QUANTITY
  17406. }
  17407. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17408. {
  17409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17410. {
  17411. tempIndex = ((gun_index==2) ? 1: 0);
  17412. }
  17413. else
  17414. {
  17415. tempIndex = gun_index;
  17416. }
  17417. for (int index = 0; index < CCS_QUANTITY; index++)
  17418. {
  17419. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17420. {
  17421. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17422. }
  17423. }// END OF CCS_QUANTITY
  17424. }
  17425. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17426. {
  17427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17428. {
  17429. tempIndex = ((gun_index==2) ? 1: 0);
  17430. }
  17431. else
  17432. {
  17433. tempIndex = gun_index;
  17434. }
  17435. for (int index = 0; index < GB_QUANTITY; index++)
  17436. {
  17437. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17438. {
  17439. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17440. }
  17441. }// END OF GB_QUANTITY
  17442. }
  17443. else if(gunType[gun_index] == GUN_TYPE_DO)
  17444. {
  17445. tempIndex = gun_index;
  17446. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17447. {
  17448. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17449. {
  17450. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17451. }
  17452. }
  17453. }
  17454. else
  17455. {
  17456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17457. {
  17458. tempIndex = 2;
  17459. }
  17460. else
  17461. {
  17462. tempIndex = gun_index;
  17463. }
  17464. for (int index = 0; index < AC_QUANTITY; index++)
  17465. {
  17466. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17467. {
  17468. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17469. }
  17470. }// END OF AC_QUANTITY
  17471. }
  17472. //Stop Transaction Time
  17473. struct timeval tmnow;
  17474. struct tm *tm;
  17475. char buf[28];//, usec_buf[6];
  17476. gettimeofday(&tmnow, NULL);
  17477. time_t t;
  17478. t = time(NULL);
  17479. /*UTC time and date*/
  17480. tm = gmtime(&t);
  17481. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17482. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17483. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17484. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17485. random_uuid(guid);
  17486. /***********************************transactionData******************************************************/
  17487. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17488. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17489. //=================================
  17490. //1. Transaction_Begin
  17491. //=================================
  17492. //============================== Energy.Active.Import.Interval ===========================================
  17493. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17494. {
  17495. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17496. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17497. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17498. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  17499. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17500. 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))
  17501. {
  17502. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17503. }
  17504. else
  17505. {
  17506. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17507. }
  17508. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17510. }
  17511. //=================================
  17512. //2. Transaction_End
  17513. //=================================
  17514. //2.1====================================== Current.Import L1 ==============================================
  17515. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17516. {
  17517. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17518. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17519. {
  17520. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17521. {
  17522. tempIndex = ((gun_index==2) ? 1: 0);
  17523. }
  17524. else
  17525. {
  17526. tempIndex = gun_index;
  17527. }
  17528. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17529. {
  17530. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17531. {
  17532. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17533. }
  17534. }// End of for CHAdeMO_QUANTITY
  17535. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17536. }
  17537. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17538. {
  17539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17540. {
  17541. tempIndex = ((gun_index==2) ? 1: 0);
  17542. }
  17543. else
  17544. {
  17545. tempIndex = gun_index;
  17546. }
  17547. for (int index = 0; index < CCS_QUANTITY; index++)
  17548. {
  17549. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17550. {
  17551. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17552. }
  17553. }// End of for CCS_QUANTITY
  17554. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17555. }
  17556. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17557. {
  17558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17559. {
  17560. tempIndex = ((gun_index==2) ? 1: 0);
  17561. }
  17562. else
  17563. {
  17564. tempIndex = gun_index;
  17565. }
  17566. for (int index = 0; index < GB_QUANTITY; index++)
  17567. {
  17568. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17569. {
  17570. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17571. }
  17572. }// End of for GB_QUANTITY
  17573. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17574. }
  17575. else if(gunType[gun_index] == GUN_TYPE_DO)
  17576. {
  17577. tempIndex = gun_index;
  17578. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17579. {
  17580. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17581. {
  17582. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17583. }
  17584. }
  17585. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17586. }
  17587. else
  17588. {
  17589. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17590. {
  17591. tempIndex = 2;
  17592. }
  17593. else
  17594. {
  17595. tempIndex = gun_index;
  17596. }
  17597. for (int index = 0; index < AC_QUANTITY; index++)
  17598. {
  17599. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17600. {
  17601. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17602. }
  17603. }// End of for AC_QUANTITY
  17604. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17605. }
  17606. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17607. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17608. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17609. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17610. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17611. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17612. }
  17613. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17614. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17615. {
  17616. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17617. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17618. {
  17619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17620. {
  17621. tempIndex = ((gun_index==2) ? 1: 0);
  17622. }
  17623. else
  17624. {
  17625. tempIndex = gun_index;
  17626. }
  17627. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17628. {
  17629. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17630. {
  17631. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17632. }
  17633. }// END OF CHAdeMO_QUANTITY
  17634. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17635. }
  17636. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17637. {
  17638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17639. {
  17640. tempIndex = ((gun_index==2) ? 1: 0);
  17641. }
  17642. else
  17643. {
  17644. tempIndex = gun_index;
  17645. }
  17646. for (int index = 0; index < CCS_QUANTITY; index++)
  17647. {
  17648. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17649. {
  17650. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17651. }
  17652. }// END OF CCS_QUANTITY
  17653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17654. }
  17655. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17656. {
  17657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17658. {
  17659. tempIndex = ((gun_index==2) ? 1: 0);
  17660. }
  17661. else
  17662. {
  17663. tempIndex = gun_index;
  17664. }
  17665. for (int index = 0; index < GB_QUANTITY; index++)
  17666. {
  17667. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17668. {
  17669. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17670. }
  17671. }// END OF GB_QUANTITY
  17672. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17673. }
  17674. else if(gunType[gun_index] == GUN_TYPE_DO)
  17675. {
  17676. tempIndex = gun_index;
  17677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17678. {
  17679. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17680. {
  17681. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17682. }
  17683. }
  17684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17685. }
  17686. else
  17687. {
  17688. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17689. {
  17690. tempIndex = 2;
  17691. }
  17692. else
  17693. {
  17694. tempIndex = gun_index;
  17695. }
  17696. for (int index = 0; index < AC_QUANTITY; index++)
  17697. {
  17698. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17699. {
  17700. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17701. }
  17702. }// END OF AC_QUANTITY
  17703. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17704. }
  17705. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17706. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17707. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17708. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17709. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17710. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17711. }
  17712. //2.3====================================== Power.Active.Import =========================================
  17713. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17714. {
  17715. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17716. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17717. {
  17718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17719. {
  17720. tempIndex = ((gun_index==2) ? 1: 0);
  17721. }
  17722. else
  17723. {
  17724. tempIndex = gun_index;
  17725. }
  17726. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17727. {
  17728. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17729. {
  17730. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17731. }
  17732. } // End for CHAdeMO_QUANTITY
  17733. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17734. }
  17735. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17736. {
  17737. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17738. {
  17739. tempIndex = ((gun_index==2) ? 1: 0);
  17740. }
  17741. else
  17742. {
  17743. tempIndex = gun_index;
  17744. }
  17745. for (int index = 0; index < CCS_QUANTITY; index++)
  17746. {
  17747. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17748. {
  17749. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17750. }
  17751. } // END for CCS_QUANTITY
  17752. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17753. }
  17754. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17755. {
  17756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17757. {
  17758. tempIndex = ((gun_index==2) ? 1: 0);
  17759. }
  17760. else
  17761. {
  17762. tempIndex = gun_index;
  17763. }
  17764. for (int index = 0; index < GB_QUANTITY; index++)
  17765. {
  17766. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17767. {
  17768. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17769. }
  17770. }// END for GB_QUANTITY
  17771. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17772. }
  17773. else if(gunType[gun_index] == GUN_TYPE_DO)
  17774. {
  17775. tempIndex = gun_index;
  17776. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17777. {
  17778. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17779. {
  17780. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17781. }
  17782. }
  17783. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17784. }
  17785. else
  17786. {
  17787. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17788. {
  17789. tempIndex = 2;
  17790. }
  17791. else
  17792. {
  17793. tempIndex = gun_index;
  17794. }
  17795. for (int index = 0; index < AC_QUANTITY; index++)
  17796. {
  17797. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17798. {
  17799. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17800. }
  17801. } // END for AC_QUANTITY
  17802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17803. }
  17804. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17806. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17807. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17809. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17810. }
  17811. //2.4====================================== Voltage L1 ====================================================
  17812. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17813. {
  17814. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17815. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17816. {
  17817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17818. {
  17819. tempIndex = ((gun_index==2) ? 1: 0);
  17820. }
  17821. else
  17822. {
  17823. tempIndex = gun_index;
  17824. }
  17825. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17826. {
  17827. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17828. {
  17829. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17830. }
  17831. } // END OF FOR CHAdeMO_QUANTITY
  17832. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17833. }
  17834. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17835. {
  17836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17837. {
  17838. tempIndex = ((gun_index==2) ? 1: 0);
  17839. }
  17840. else
  17841. {
  17842. tempIndex = gun_index;
  17843. }
  17844. for (int index = 0; index < CCS_QUANTITY; index++)
  17845. {
  17846. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17847. {
  17848. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17849. }
  17850. } // END OF FOR CCS_QUANTITY
  17851. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17852. }
  17853. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17854. {
  17855. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17856. {
  17857. tempIndex = ((gun_index==2) ? 1: 0);
  17858. }
  17859. else
  17860. {
  17861. tempIndex = gun_index;
  17862. }
  17863. for (int index = 0; index < GB_QUANTITY; index++)
  17864. {
  17865. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17866. {
  17867. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17868. }
  17869. } // END OF FOR GB_QUANTITY
  17870. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17871. }
  17872. else if(gunType[gun_index] == GUN_TYPE_DO)
  17873. {
  17874. tempIndex = gun_index;
  17875. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17876. {
  17877. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17878. {
  17879. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17880. }
  17881. }
  17882. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17883. }
  17884. else
  17885. {
  17886. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17887. {
  17888. tempIndex = 2;
  17889. }
  17890. else
  17891. {
  17892. tempIndex = gun_index;
  17893. }
  17894. for (int index = 0; index < AC_QUANTITY; index++)
  17895. {
  17896. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17897. {
  17898. 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
  17899. }
  17900. } // END OF FOR AC_QUANTITY
  17901. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17902. }
  17903. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17904. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17905. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17906. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17907. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17908. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17909. }
  17910. //2.5============================================== End SoC =========================================================
  17911. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17912. {
  17913. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17914. 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))
  17915. {
  17916. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17917. {
  17918. tempIndex = ((gun_index==2) ? 1: 0);
  17919. }
  17920. else
  17921. {
  17922. tempIndex = gun_index;
  17923. }
  17924. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17925. {
  17926. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17927. {
  17928. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17929. {
  17930. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17931. }
  17932. }
  17933. }
  17934. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17935. {
  17936. for (int index = 0; index < CCS_QUANTITY; index++)
  17937. {
  17938. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17939. {
  17940. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17941. }
  17942. }
  17943. }
  17944. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17945. {
  17946. for (int index = 0; index < GB_QUANTITY; index++)
  17947. {
  17948. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17949. {
  17950. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17951. }
  17952. }
  17953. }
  17954. else if(gunType[gun_index] == GUN_TYPE_DO)
  17955. {
  17956. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17957. {
  17958. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17959. {
  17960. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17961. }
  17962. }
  17963. }
  17964. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17965. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17966. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17967. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17968. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17969. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17970. } // END FOR DC CASE
  17971. }
  17972. //2.6====================================== Current.Import L2 ==============================================
  17973. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17974. {
  17975. // AC 3 phase L2 current
  17976. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17977. {
  17978. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17979. {
  17980. tempIndex = 2;
  17981. }
  17982. else
  17983. {
  17984. tempIndex = gun_index;
  17985. }
  17986. for (int index = 0; index < AC_QUANTITY; index++)
  17987. {
  17988. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17989. {
  17990. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17991. }
  17992. }// End of for AC_QUANTITY
  17993. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17994. }
  17995. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17996. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17998. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17999. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18000. }
  18001. //2.7====================================== Current.Import L3 ==============================================
  18002. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18003. {
  18004. // AC 3 phase L3 current
  18005. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18006. {
  18007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18008. {
  18009. tempIndex = 2;
  18010. }
  18011. else
  18012. {
  18013. tempIndex = gun_index;
  18014. }
  18015. for (int index = 0; index < AC_QUANTITY; index++)
  18016. {
  18017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18018. {
  18019. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18020. }
  18021. }// End of for AC_QUANTITY
  18022. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18023. }
  18024. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18025. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18026. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18027. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18028. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18029. }
  18030. //2.9====================================== Voltage L2 ====================================================
  18031. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18032. {
  18033. // AC 3 phase L2 volatge
  18034. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18035. {
  18036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18037. {
  18038. tempIndex = 2;
  18039. }
  18040. else
  18041. {
  18042. tempIndex = gun_index;
  18043. }
  18044. for (int index = 0; index < AC_QUANTITY; index++)
  18045. {
  18046. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18047. {
  18048. 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
  18049. }
  18050. } // END OF FOR AC_QUANTITY
  18051. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18052. }
  18053. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18054. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18058. }
  18059. //2.10====================================== Voltage L3 ====================================================
  18060. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18061. {
  18062. // AC 3 phase L3 volatge
  18063. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18064. {
  18065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18066. {
  18067. tempIndex = 2;
  18068. }
  18069. else
  18070. {
  18071. tempIndex = gun_index;
  18072. }
  18073. for (int index = 0; index < AC_QUANTITY; index++)
  18074. {
  18075. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18076. {
  18077. 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
  18078. }
  18079. } // END OF FOR AC_QUANTITY
  18080. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18081. }
  18082. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18083. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18084. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18085. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18087. }
  18088. //====================== Start SoC ================================
  18089. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18090. {
  18091. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18092. 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))
  18093. {
  18094. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18095. {
  18096. tempIndex = ((gun_index==2) ? 1: 0);
  18097. }
  18098. else
  18099. {
  18100. tempIndex = gun_index;
  18101. }
  18102. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18103. {
  18104. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18105. {
  18106. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18107. {
  18108. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18109. }
  18110. }
  18111. }
  18112. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18113. {
  18114. for (int index = 0; index < CCS_QUANTITY; index++)
  18115. {
  18116. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18117. {
  18118. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18119. }
  18120. }
  18121. }
  18122. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18123. {
  18124. for (int index = 0; index < GB_QUANTITY; index++)
  18125. {
  18126. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18127. {
  18128. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18129. }
  18130. }
  18131. }
  18132. else if(gunType[gun_index] == GUN_TYPE_DO)
  18133. {
  18134. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18135. {
  18136. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18137. {
  18138. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18139. }
  18140. }
  18141. }
  18142. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18143. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18144. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18145. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18146. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18147. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18148. } // END FOR DC CASE
  18149. }
  18150. //======================================== Message create ==============================================
  18151. json_object *StopTransaction = json_object_new_object();
  18152. json_object *transactionDatas = json_object_new_array();
  18153. json_object *sampledValues = json_object_new_array();
  18154. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  18155. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  18156. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  18157. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  18158. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  18159. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18160. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  18161. {
  18162. json_object *transactionData = json_object_new_object();
  18163. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18164. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18165. {
  18166. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18167. {
  18168. json_object *sampledValue = json_object_new_object();
  18169. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18170. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18171. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18172. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18173. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18174. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18175. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18176. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18177. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18178. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18179. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18180. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18181. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18182. json_object_array_add(sampledValues, sampledValue);
  18183. }
  18184. }
  18185. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18186. json_object_array_add(transactionDatas, transactionData);
  18187. }
  18188. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18189. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18190. ,MESSAGE_TYPE_CALL
  18191. ,guid
  18192. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18193. json_object_put(StopTransaction);
  18194. // Check File "TempStopTransaction" Exist
  18195. if((access(TempStopTransaction,F_OK))!=-1)
  18196. {
  18197. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18198. fclose(fopen(TempStopTransaction, "w"));
  18199. }
  18200. else
  18201. {
  18202. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18203. FILE *log = fopen(TempStopTransaction, "w+");
  18204. if(log == NULL)
  18205. {
  18206. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18207. return ;
  18208. }
  18209. else
  18210. {
  18211. fclose(log);
  18212. }
  18213. }
  18214. //Add TempStopTransaction | Update TempStopTransaction
  18215. // open file for writing
  18216. FILE *outfile;
  18217. outfile = fopen (TempStopTransaction, "a");
  18218. //DEBUG_INFO("data = %s\n", queuedata);
  18219. fputs(queuedata, outfile);
  18220. fputs("\n", outfile);
  18221. fclose (outfile);
  18222. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18223. }
  18224. void checkTempStopTransaction(int gun_index)
  18225. {
  18226. FILE *fptr1;
  18227. char ch;
  18228. char str[QUEUE_MESSAGE_LENGTH]={0};
  18229. char guid[37]={0};
  18230. char tempdata[65]={0};
  18231. char connectorStr[2]={0};
  18232. char TempStopTransaction[256];
  18233. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18234. fptr1 = fopen(TempStopTransaction, "r");
  18235. //TempStopTransaction格式: 槍號,StopTransaction封包
  18236. if (!fptr1)
  18237. {
  18238. //printf(" File not found or unable to open the input file!!\n");
  18239. return ;
  18240. }
  18241. ch=fgetc(fptr1);
  18242. //printf(" Now the content of the file %s is : \n",fname);
  18243. rewind(fptr1);
  18244. if(ch!=EOF)
  18245. {
  18246. // copy all contents to the temporary file except the specific line
  18247. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18248. {
  18249. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18250. if(str[0]=='\0')
  18251. {
  18252. break;
  18253. }
  18254. //TempStopTransaction格式: 槍號,StopTransaction封包
  18255. strncpy(connectorStr, str, 1);
  18256. if(atoi(connectorStr) != (gun_index+1))
  18257. {
  18258. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18259. fclose(fptr1);
  18260. return ;
  18261. }
  18262. //random_uuid(guid);
  18263. strncpy(guid, str+6, 36); //copy guid
  18264. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18265. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18266. {
  18267. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18268. }
  18269. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18270. OCPP_insert_transaction_msg(NO, str);
  18271. memset(str,0,ARRAY_SIZE(str));
  18272. }
  18273. }
  18274. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18275. fclose(fptr1);
  18276. remove(TempStopTransaction); // remove the original file
  18277. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18278. }
  18279. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18280. {
  18281. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18282. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18283. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18284. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18285. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18286. }
  18287. int GetWebSocketPingInterval(void)
  18288. {
  18289. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18290. }
  18291. int GetServerSign(void)
  18292. {
  18293. return server_sign;
  18294. }
  18295. uint8_t GetOcppSecurityProfile()
  18296. {
  18297. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18298. }
  18299. void GetOcppChargerBoxId(uint8_t *data)
  18300. {
  18301. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18302. }
  18303. void GetOcppSecurityPassword(uint8_t *data)
  18304. {
  18305. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18306. }
  18307. void SetOcppVersion(uint8_t *version)
  18308. {
  18309. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18310. DEBUG_INFO("ocpp version: %s\n", version);
  18311. if(strstr((char*)version, "ocpp1.6") != NULL)
  18312. {
  18313. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18314. }
  18315. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18316. {
  18317. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18318. system("pkill OcppBackend");
  18319. }
  18320. }
  18321. void SetServerSign(int value)
  18322. {
  18323. server_sign = value;
  18324. }
  18325. int GetBootNotificationInterval(void)
  18326. {
  18327. return BootNotificationInterval;
  18328. }
  18329. int GetInternetConn(void)
  18330. {
  18331. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18332. }
  18333. int GetBackendConnectionTimeout(void)
  18334. {
  18335. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18336. }
  18337. int isConnectorInitMode(int gun_index)
  18338. {
  18339. int tempIndex = 0;
  18340. int result = TRUE;
  18341. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18342. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18343. {
  18344. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18345. {
  18346. tempIndex = ((gun_index==2) ? 1: 0);
  18347. }
  18348. else
  18349. {
  18350. tempIndex = gun_index;
  18351. }
  18352. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18353. {
  18354. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18355. {
  18356. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18357. } //end of the same index
  18358. }//end of for CHAdeMO_QUANTITY
  18359. }
  18360. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18361. {
  18362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18363. {
  18364. tempIndex = ((gun_index==2) ? 1: 0);
  18365. }
  18366. else
  18367. {
  18368. tempIndex = gun_index;
  18369. }
  18370. for (int index = 0; index < CCS_QUANTITY; index++)
  18371. {
  18372. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18373. {
  18374. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18375. } //end of the same index
  18376. } // end of for CCS_QUANTITY
  18377. }
  18378. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18379. {
  18380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18381. {
  18382. tempIndex = ((gun_index==2) ? 1: 0);
  18383. }
  18384. else
  18385. {
  18386. tempIndex = gun_index;
  18387. }
  18388. for (int index = 0; index < GB_QUANTITY; index++)
  18389. {
  18390. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18391. {
  18392. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18393. } //end of the same index
  18394. } // end of for GB_QUANTITY
  18395. }
  18396. else if(gunType[gun_index] == GUN_TYPE_DO)
  18397. {
  18398. tempIndex = gun_index;
  18399. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18400. {
  18401. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18402. {
  18403. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18404. } //end of the same index
  18405. }
  18406. }
  18407. else
  18408. {
  18409. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18410. {
  18411. tempIndex = 2;
  18412. }
  18413. else
  18414. {
  18415. tempIndex = gun_index;
  18416. }
  18417. for (int index = 0; index < AC_QUANTITY; index++)
  18418. {
  18419. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18420. {
  18421. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18422. }//end of the same index
  18423. }//end of for AC_QUANTITY
  18424. }
  18425. return result;
  18426. }
  18427. void refreshProcDogTimer()
  18428. {
  18429. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18430. }
  18431. void InitialSystemValue(void)
  18432. {
  18433. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18434. locallistVersion=0;
  18435. BootNotificationInterval = 0;
  18436. authorizeRetryTimes = 0;
  18437. GunStatusInterval = 10;
  18438. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18439. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18440. //Hear Beat
  18441. HeartBeatWithNOResponse = 0;
  18442. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18443. FirstHeartBeat = 0;
  18444. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18445. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18446. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18447. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18448. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18449. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18450. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18451. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18452. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18453. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18454. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18455. //Status && ConnectorPlugIn Setting
  18456. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18457. {
  18458. ChademoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18459. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18460. }
  18461. for (int index = 0; index < CCS_QUANTITY; index++)
  18462. {
  18463. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18464. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18465. }
  18466. for (int index = 0; index < GB_QUANTITY; index++)
  18467. {
  18468. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18469. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18470. }
  18471. for (int index = 0; index < AC_QUANTITY; index++)
  18472. {
  18473. AcPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18474. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18475. }
  18476. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18477. {
  18478. DoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18479. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18480. }
  18481. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18482. {
  18483. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18484. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18485. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18486. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18487. //memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18488. memset(&ShmOCPP16DataPH->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16DataPH->StatusNotification[gun_index].Status));
  18489. }
  18490. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18491. refreshStartTimer(&clientTime.Heartbeat);
  18492. sleep(1);
  18493. }
  18494. void LWS_Send(char *str)
  18495. {
  18496. //=====================================================
  18497. // Check InternetConn 0: disconnected, 1: connected
  18498. //====================================================
  18499. if(GetOcppConnStatus() == 0)
  18500. {
  18501. DEBUG_INFO("offline now !!!\n");
  18502. return;
  18503. }
  18504. // Only disable isWebsocketSendable operation initiated by charger
  18505. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18506. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18507. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18508. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18509. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18510. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18511. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18512. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18513. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18514. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18515. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18516. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18517. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18518. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18519. {
  18520. isWebsocketSendable = 0;
  18521. }
  18522. pthread_mutex_lock(&lock_send);
  18523. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18524. sprintf((char *)SendBuffer, "%s", str);
  18525. SendBufLen = strlen(str);
  18526. pthread_mutex_unlock(&lock_send);
  18527. lws_callback_on_writable(wsi_client);
  18528. //lws_service(context, 0);
  18529. //sleep(1);
  18530. }
  18531. void LWS_SendNow(char *str)
  18532. {
  18533. //=====================================================
  18534. // Check InternetConn 0: disconnected, 1: connected
  18535. //====================================================
  18536. if(GetOcppConnStatus() == 0)
  18537. {
  18538. DEBUG_INFO("offline now !!!\n");
  18539. return;
  18540. }
  18541. // Only disable isWebsocketSendable operation initiated by charger
  18542. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18543. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18544. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18545. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18546. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18547. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18548. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18549. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18550. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18551. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18552. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18553. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18554. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18555. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18556. {
  18557. isWebsocketSendable = 0;
  18558. }
  18559. pthread_mutex_lock(&lock_send);
  18560. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18561. sprintf((char *)SendBuffer, "%s", str);
  18562. SendBufLen = strlen(str);
  18563. pthread_mutex_unlock(&lock_send);
  18564. lws_callback_on_writable(wsi_client);
  18565. lws_service(context, 0);
  18566. //sleep(1);
  18567. }