MessageHandler.c 964 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  56. //========================================
  57. // OCPP status/previous related variables
  58. //========================================
  59. static int GunStatusInterval = 10;
  60. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  61. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  62. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  63. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  64. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  65. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  66. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  67. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  68. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  69. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  70. static int TransactionMessageAttemptsValue = 0;
  71. static int TransactionMessageRetryIntervalValue = 0;
  72. static int TempMeterValueInterval = 0;
  73. static struct OCPPAuthLocalElemet
  74. {
  75. int listVersionInt;
  76. char idTagstr[21];
  77. char parentIdTag[21];
  78. char expiryDate[36];
  79. char idTagstatus[16];
  80. }idTagQuery;
  81. //============================================
  82. // OCPP MeterValue request flag
  83. //============================================
  84. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  85. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  86. //============================================
  87. // OCPP HeartBeat Response Not Receive Counts
  88. //============================================
  89. static int HeartBeatWithNOResponse = 0;
  90. //============================================
  91. // OCPP California Pricing Requirements
  92. //============================================
  93. static char dmsVersion[21] = {0};
  94. extern sqlite3 *db;
  95. int TransactionMessageAttemptsGet(void);
  96. int TransactionMessageRetryIntervalGet(void);
  97. int GetOcppConnStatus(void);
  98. void SetOcppConnStatus(uint8_t status);
  99. int setKeyValue(char *key, char *value);
  100. void OCPP_get_TableAuthlocalAllData(void);
  101. void processUnkownKey(void);
  102. struct InterLock
  103. {
  104. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  105. unsigned char isGetDiagnosticGoing:1;
  106. unsigned char isUpdateFirmwareGoing:1;
  107. }interLock;
  108. struct ClientTime
  109. {
  110. struct timespec Heartbeat;
  111. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  112. struct timespec StartTransaction;
  113. struct timespec StopTransaction;
  114. struct timespec MeterValues[CONNECTOR_QUANTITY];
  115. struct timespec RemoteStartWait;
  116. struct timespec TcciQueryDeduct;
  117. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  118. }clientTime;
  119. typedef union
  120. {
  121. //Operations Initiated by Central System
  122. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  123. struct
  124. {
  125. //CsMsgValue[0]
  126. unsigned char StatusNotificationReq:1; //bit 0,
  127. unsigned char StatusNotificationConf:1; //bit 1,
  128. unsigned char TriggerMeterValue:1; //bit 2,
  129. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  130. unsigned char isOnCharging:1; //bit 4.
  131. unsigned char :3; //bit 5~7
  132. }bits[CONNECTOR_QUANTITY];
  133. }CpinitiateMsg;
  134. CpinitiateMsg cpinitateMsg;
  135. //GetConfiguration Array
  136. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  137. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  138. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  139. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  140. static char *ChargePointErrorCodeStr[] = {
  141. MACROSTR(ConnectorLockFailure),
  142. MACROSTR(EVCommunicationError),
  143. MACROSTR(GroundFailure),
  144. MACROSTR(HighTemperature),
  145. MACROSTR(InternalError),
  146. MACROSTR(LocalListConflict),
  147. MACROSTR(NoError),
  148. MACROSTR(OtherError),
  149. MACROSTR(OverCurrentFailure),
  150. MACROSTR(OverVoltage),
  151. MACROSTR(PowerMeterFailure),
  152. MACROSTR(PowerSwitchFailure),
  153. MACROSTR(ReaderFailure),
  154. MACROSTR(ResetFailure),
  155. MACROSTR(UnderVoltage),
  156. MACROSTR(WeakSignal)
  157. };
  158. static char * ChargePointStatusStr[] = {
  159. MACROSTR(Available),
  160. MACROSTR(Preparing),
  161. MACROSTR(Charging),
  162. MACROSTR(SuspendedEVSE),
  163. MACROSTR(SuspendedEV),
  164. MACROSTR(Finishing),
  165. MACROSTR(Reserved),
  166. MACROSTR(Unavailable),
  167. MACROSTR(Faulted)
  168. };
  169. static char *RegistrationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Pending),
  172. MACROSTR(Rejected)
  173. };
  174. static char *AvailabilityTypeStr[] = {
  175. MACROSTR(Inoperative),
  176. MACROSTR(Operative)
  177. };
  178. static char *AvailabilityStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(Scheduled)
  182. };
  183. static char *ConfigurationStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected),
  186. MACROSTR(RebootRequired),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearCacheStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Rejected)
  192. };
  193. static char *ChargingProfilePurposeTypeStr[] = {
  194. MACROSTR(ChargePointMaxProfile),
  195. MACROSTR(TxDefaultProfile),
  196. MACROSTR(TxProfile)
  197. };
  198. static char *ChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Rejected),
  201. MACROSTR(NotSupported)
  202. };
  203. static char *ClearChargingProfileStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Unknown)
  206. };
  207. static char *GetCompositeScheduleStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *UpdateTypeStr[] = {
  212. MACROSTR(Differential),
  213. MACROSTR(Full)
  214. };
  215. static char *UpdateStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Failed),
  218. MACROSTR(NotSupported),
  219. MACROSTR(VersionMismatch)
  220. };
  221. static char *RemoteStartStopStatusStr[] = {
  222. MACROSTR(Accepted),
  223. MACROSTR(Rejected)
  224. };
  225. static char *ReservationStatusStr[] = {
  226. MACROSTR(Accepted),
  227. MACROSTR(Faulted),
  228. MACROSTR(Occupied),
  229. MACROSTR(Rejected),
  230. MACROSTR(Unavailable)
  231. };
  232. static char *ResetTypeStr[] = {
  233. MACROSTR(Hard),
  234. MACROSTR(Soft)
  235. };
  236. static char *ResetStatusStr[] = {
  237. MACROSTR(Accepted),
  238. MACROSTR(Rejected)
  239. };
  240. static char * DiagnosticsStatusStr[] = {
  241. MACROSTR(Idle),
  242. MACROSTR(Uploaded),
  243. MACROSTR(UploadFailed),
  244. MACROSTR(Uploading)
  245. };
  246. static char * FirmwareStatusStr[] = {
  247. MACROSTR(Downloaded),
  248. MACROSTR(DownloadFailed),
  249. MACROSTR(Downloading),
  250. MACROSTR(Idle),
  251. MACROSTR(InstallationFailed),
  252. MACROSTR(Installing),
  253. MACROSTR(Installed)
  254. };
  255. static char * MessageTriggerStr[] = {
  256. MACROSTR(BootNotification),
  257. MACROSTR(DiagnosticsStatusNotification),
  258. MACROSTR(FirmwareStatusNotification),
  259. MACROSTR(Heartbeat),
  260. MACROSTR(MeterValues),
  261. MACROSTR(StatusNotification)
  262. };
  263. static char * TriggerMessageStatusStr[] = {
  264. MACROSTR(Accepted),
  265. MACROSTR(Rejected),
  266. MACROSTR(NotImplemented)
  267. };
  268. static char * UnlockStatusStr[] = {
  269. MACROSTR(Unlocked),
  270. MACROSTR(UnlockFailed),
  271. MACROSTR(NotSupported)
  272. };
  273. #if 0
  274. static char * StopTransactionReasonStr[] = {
  275. MACROSTR(EmergencyStop),
  276. MACROSTR(EVDisconnected),
  277. MACROSTR(HardReset),
  278. MACROSTR(Local),
  279. MACROSTR(Other),
  280. MACROSTR(PowerLoss),
  281. MACROSTR(Reboot),
  282. MACROSTR(Remote),
  283. MACROSTR(SoftReset),
  284. MACROSTR(UnlockCommand),
  285. MACROSTR(DeAuthorized)
  286. };
  287. #endif
  288. static char * CancelReservationStatusStr[] = {
  289. MACROSTR(Accepted),
  290. MACROSTR(Rejected)
  291. };
  292. static char * ReadingContextStr[] = {
  293. MACROSTR(Interruption.Begin),
  294. MACROSTR(Interruption.End),
  295. MACROSTR(Other),
  296. MACROSTR(Sample.Clock),
  297. MACROSTR(Sample.Periodic),
  298. MACROSTR(Transaction.Begin),
  299. MACROSTR(Transaction.End),
  300. MACROSTR(Trigger)
  301. };
  302. static char * ValueFormatStr[] = {
  303. MACROSTR(Raw),
  304. MACROSTR(SignedData)
  305. };
  306. static char * MeasurandStr[] = {
  307. MACROSTR(Current.Export),
  308. MACROSTR(Current.Import),
  309. MACROSTR(Current.Offered),
  310. MACROSTR(Energy.Active.Export.Register),
  311. MACROSTR(Energy.Active.Import.Register),
  312. MACROSTR(Energy.Reactive.Export.Register),
  313. MACROSTR(Energy.Reactive.Import.Register),
  314. MACROSTR(Energy.Active.Export.Interval),
  315. MACROSTR(Energy.Active.Import.Interval),
  316. MACROSTR(Energy.Reactive.Export.Interval),
  317. MACROSTR(Energy.Reactive.Import.Interval),
  318. MACROSTR(Frequency),
  319. MACROSTR(Power.Active.Export),
  320. MACROSTR(Power.Active.Import),
  321. MACROSTR(Power.Factor),
  322. MACROSTR(Power.Offered),
  323. MACROSTR(Power.Reactive.ExportMACROSTR),
  324. MACROSTR(Power.Reactive.Import),
  325. MACROSTR(RPM),
  326. MACROSTR(SoC),
  327. MACROSTR(Temperature),
  328. MACROSTR(Voltage)
  329. };
  330. static char * LocationStr[] = {
  331. MACROSTR(Body),
  332. MACROSTR(Cable),
  333. MACROSTR(EV),
  334. MACROSTR(Inlet),
  335. MACROSTR(Outlet)
  336. };
  337. static char * PhaseStr[] = {
  338. MACROSTR(L1),
  339. MACROSTR(L2),
  340. MACROSTR(L3),
  341. MACROSTR(N),
  342. MACROSTR(L1-N),
  343. MACROSTR(L2-N),
  344. MACROSTR(L3-N),
  345. MACROSTR(L1-L2),
  346. MACROSTR(L2-L3),
  347. MACROSTR(L3-L1)
  348. };
  349. static char * UnitOfMeasureStr[] = {
  350. MACROSTR(Wh),
  351. MACROSTR(kWh),
  352. MACROSTR(varh),
  353. MACROSTR(kvarh),
  354. MACROSTR(W),
  355. MACROSTR(kW),
  356. MACROSTR(VA),
  357. MACROSTR(kVA),
  358. MACROSTR(var),
  359. MACROSTR(kvar),
  360. MACROSTR(A),
  361. MACROSTR(V),
  362. MACROSTR(Celsius),
  363. MACROSTR(Fahrenheit),
  364. MACROSTR(K),
  365. MACROSTR(Percent)
  366. };
  367. //=========================================
  368. // Save configuration
  369. //=========================================
  370. int runShellCmd(const char*cmd)
  371. {
  372. int result = FAIL;
  373. char buf[256];
  374. FILE *fp;
  375. fp = popen(cmd, "r");
  376. if(fp != NULL)
  377. {
  378. while(fgets(buf, sizeof(buf), fp) != NULL)
  379. {
  380. DEBUG_INFO("%s\n", buf);
  381. }
  382. result = PASS;
  383. }
  384. pclose(fp);
  385. return result;
  386. }
  387. int StoreUsrConfigData(struct SysConfigData *UsrData)
  388. {
  389. int result = PASS;
  390. int fd,wrd;
  391. unsigned int i,Chk;
  392. unsigned char *ptr, *BufTmp;
  393. int MtdBlockSize = 0x300000;
  394. Chk=0;
  395. ptr=(unsigned char *)UsrData;
  396. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  397. {
  398. memset(BufTmp,0,MtdBlockSize);
  399. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  400. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  401. Chk+=*(BufTmp+i);
  402. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  403. // Output configuration to file.
  404. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  405. if (fd < 0)
  406. {
  407. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  408. free(BufTmp);
  409. return 0;
  410. }
  411. wrd=write(fd, BufTmp, MtdBlockSize);
  412. close(fd);
  413. if(wrd<MtdBlockSize)
  414. {
  415. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  416. free(BufTmp);
  417. return 0;
  418. }
  419. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  420. DEBUG_INFO("Erase /dev/mtd10.\n");
  421. runShellCmd("flash_erase /dev/mtd10 0 0");
  422. DEBUG_INFO("Write /dev/mtd10.\n");
  423. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  424. DEBUG_INFO("Erase /dev/mtd11.\n");
  425. runShellCmd("flash_erase /dev/mtd11 0 0");
  426. DEBUG_INFO("Write /dev/mtd11.\n");
  427. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  428. system("rm -f /mnt/EvseConfig.bin");
  429. DEBUG_INFO("EvseConfig write to flash OK\n");
  430. }
  431. else
  432. {
  433. DEBUG_ERROR("alloc BlockSize NG\r\n");
  434. result = FAIL;
  435. }
  436. if(BufTmp!=NULL)
  437. free(BufTmp);
  438. return result;
  439. }
  440. //=========================================
  441. // Sqlite3 related function
  442. //=========================================
  443. static int selectSqlCount = 0;
  444. static int callback(void *data, int argc, char **argv, char **azColName){
  445. int i;
  446. //printf("%s: ", (const char*)data);
  447. selectSqlCount = argc;
  448. for(i = 0; i<argc; i++){
  449. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  450. }
  451. //printf("\n");
  452. return 0;
  453. }
  454. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  455. //int i;
  456. //printf("%s:\n", (const char*)data);
  457. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  458. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  459. return 0;
  460. }
  461. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  462. //printf("%s:\n", (const char*)data);
  463. //idTag
  464. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  465. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  466. //parentIdTag
  467. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  468. //expir_date
  469. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  470. //status
  471. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  472. //version
  473. if(columenCount > 5)
  474. idTagQuery.listVersionInt = atoi(columnValue[5]);
  475. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  476. return 0;
  477. }
  478. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  479. {
  480. // localversion = argv[5] ? atoi(argv[5]) : 0;
  481. // printf("localversion=%d\n", localversion);
  482. return 0;
  483. }
  484. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  485. {
  486. for (int i = 0; i < n_columns; i++)
  487. {
  488. DEBUG_INFO("%s\t", col_values[i]);
  489. }
  490. DEBUG_INFO("\n");
  491. return 0;
  492. }
  493. int OCPP_cleanLocalCache()
  494. {
  495. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  496. char *errMsg = 0;
  497. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  498. if (SQLITE_OK != rc)
  499. {
  500. DEBUG_INFO("SQL error: %s\n",errMsg);
  501. return FALSE;
  502. }
  503. return TRUE;
  504. }
  505. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  506. {
  507. int isSuccess = TRUE;
  508. int ret = 0;
  509. //const char* data = "Callback function called";
  510. char sql[300];
  511. char zErrMsg[200];
  512. memset(sql, 0, 300);
  513. memset(zErrMsg, 0, 200);
  514. 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);
  515. //* Execute SQL statement */
  516. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  517. if( ret != SQLITE_OK )
  518. {
  519. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  520. isSuccess = FALSE;
  521. }
  522. return isSuccess;
  523. }
  524. void OCPP_getIdTagFromLocalCache(char idTag[])
  525. {
  526. int rc = 0;
  527. char sql[100];
  528. char zErrMsg[100];
  529. memset(sql, 0, 100);
  530. memset(zErrMsg, 0, 100);
  531. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  532. memset(&idTagQuery, 0, sizeof(idTagQuery));
  533. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  534. /* Execute SQL statement */
  535. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  536. if( rc != SQLITE_OK )
  537. {
  538. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  539. }
  540. }
  541. void OCPP_getListVerion()
  542. {
  543. int rc = 0;
  544. // const char* data = "Callback function called";
  545. char sql[100];
  546. char zErrMsg[100];
  547. memset(sql, 0, 100);
  548. memset(zErrMsg, 0, 100);
  549. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  550. /* Execute SQL statement */
  551. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  552. if( rc != SQLITE_OK )
  553. {
  554. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  555. }
  556. }
  557. void OCPP_get_TableAuthlocalAllData(void)
  558. {
  559. int rc = 0;
  560. char sql[100];
  561. char zErrMsg[100];
  562. memset(sql, 0, 100);
  563. memset(zErrMsg, 0, 100);
  564. sprintf(sql,"select * from ocpp_auth_local ");
  565. /* Execute SQL statement */
  566. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  567. if( rc != SQLITE_OK )
  568. {
  569. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  570. }
  571. //return ver;
  572. }
  573. int OCPP_cleanLocalList()
  574. {
  575. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  576. char *errMsg = 0;
  577. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  578. if (SQLITE_OK != rc)
  579. {
  580. DEBUG_INFO("%s\n",errMsg);
  581. return FALSE;
  582. }
  583. return TRUE;
  584. }
  585. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  586. {
  587. int isSuccess = FALSE;
  588. int ret = 0;
  589. //const char* data = "Callback function called";
  590. char sql[300];
  591. char zErrMsg[200];
  592. memset(sql, 0, 300);
  593. memset(zErrMsg, 0, 200);
  594. 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);
  595. //* Execute SQL statement */
  596. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  597. if( ret != SQLITE_OK )
  598. {
  599. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  600. return isSuccess;
  601. }
  602. memset(sql, 0, 300);
  603. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  604. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  605. if( ret != SQLITE_OK )
  606. {
  607. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  608. return isSuccess;
  609. }
  610. isSuccess = TRUE;
  611. return isSuccess;
  612. }
  613. void OCPP_getIdTagFromLocalList(char idTag[])
  614. {
  615. int rc = 0;
  616. // const char* data = "Callback function called";
  617. char sql[100];
  618. char zErrMsg[100];
  619. memset(sql, 0, 100);
  620. memset(zErrMsg, 0, 100);
  621. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  622. memset(&idTagQuery, 0, sizeof(idTagQuery));
  623. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  624. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  625. /* Execute SQL statement */
  626. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  627. if( rc != SQLITE_OK )
  628. {
  629. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  630. }
  631. //return ver;
  632. }
  633. void OCPP_deleteIdTagFromLocalList(char idTag[])
  634. {
  635. //int ver = 0;
  636. //int isSuccess = FALSE;
  637. int rc = 0;
  638. char sql[100];
  639. char zErrMsg[100];
  640. memset(sql, 0, 100);
  641. memset(zErrMsg, 0, 100);
  642. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  643. //* Execute SQL statement */
  644. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  645. if( rc != SQLITE_OK )
  646. {
  647. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  648. }
  649. }
  650. int getCurrentYear()
  651. {
  652. int result = 0;
  653. time_t CurrentTime;
  654. struct tm *tm;
  655. CurrentTime = time(NULL);
  656. tm=localtime(&CurrentTime);
  657. result = (tm->tm_year + 1900);
  658. return result;
  659. }
  660. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  661. {
  662. int result = PASS;
  663. char* errMsg = NULL;
  664. char sqlStr[8192];
  665. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  666. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  667. {
  668. result = FAIL;
  669. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  670. }
  671. 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));
  672. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  673. {
  674. result = FAIL;
  675. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  676. }
  677. return result;
  678. }
  679. 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)
  680. {
  681. int result = PASS;
  682. char* errMsg = NULL;
  683. char sqlStr[8192];
  684. 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');",
  685. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  686. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  687. {
  688. result = FAIL;
  689. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  690. }
  691. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  692. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  693. {
  694. result = FAIL;
  695. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  696. }
  697. return result;
  698. }
  699. int OCPP_update_deduct_info(int txId, char *creditNo)
  700. {
  701. int result = PASS;
  702. char* errMsg = NULL;
  703. char sqlStr[8192];
  704. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  705. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  706. {
  707. result = FAIL;
  708. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  709. }
  710. return result;
  711. }
  712. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  713. {
  714. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  715. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  716. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  717. atoi(columnValue[1]),
  718. columnValue[2],
  719. atoi(columnValue[3])==1?"true":"false",
  720. atoi(columnValue[4])==1?"true":"false",
  721. columnValue[5],
  722. columnValue[9]);
  723. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  724. return 0;
  725. }
  726. void OCPP_query_deduct_info()
  727. {
  728. int rc = 0;
  729. char sql[100];
  730. char zErrMsg[100];
  731. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  732. /* Execute SQL statement */
  733. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  734. if( rc != SQLITE_OK )
  735. {
  736. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  737. }
  738. }
  739. void reportReaderStatus(int gun_index)
  740. {
  741. struct timeval tmnow;
  742. struct tm *tm;
  743. char buf[28];//, usec_buf[6];
  744. gettimeofday(&tmnow, NULL);
  745. time_t t;
  746. t = time(NULL);
  747. /*UTC time and date*/
  748. tm = gmtime(&t);
  749. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  750. #if 0 // remove temporally
  751. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  752. strcat(buf,".");
  753. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  754. strcat(buf,usec_buf);
  755. #endif
  756. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  757. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  758. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  759. (gun_index+1),
  760. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  761. buf,
  762. ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index],
  763. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].creditNo,
  764. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  765. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  766. }
  767. //==========================================
  768. // Check time passed since today
  769. //==========================================
  770. long long DiffTimebWithNow(struct timeb ST)
  771. {
  772. //return milli-second
  773. struct timeb ET;
  774. long long StartTime,StopTime;
  775. ftime(&ET);
  776. StartTime=(long long)ST.time;
  777. StopTime=(long long)ET.time;
  778. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  779. }
  780. int getTimePassSinceToday(uint8_t gun_index)
  781. {
  782. int result = -1;
  783. static time_t lastTime[4];
  784. time_t t;
  785. struct tm *tmStartToday;
  786. struct timeb tbStartToday;
  787. t=time(NULL);
  788. if(difftime(t, lastTime[gun_index])>0)
  789. {
  790. tmStartToday=localtime(&t);
  791. tmStartToday->tm_hour = 0;
  792. tmStartToday->tm_min = 0;
  793. tmStartToday->tm_sec = 0;
  794. tbStartToday.time = mktime(tmStartToday);
  795. tbStartToday.millitm = 0;
  796. result = DiffTimebWithNow(tbStartToday)/1000;
  797. lastTime[gun_index] = t;
  798. }
  799. return result;
  800. }
  801. void getNowDatetime(uint8_t *data)
  802. {
  803. time_t t = time(NULL);
  804. struct tm tm = *localtime(&t);
  805. 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);
  806. }
  807. int syncDateTimeRTC(uint8_t *data)
  808. {
  809. struct ParsingResult
  810. {
  811. int result;
  812. int scanedElement;
  813. int year;
  814. int month;
  815. int mday;
  816. int hour;
  817. int min;
  818. int sec;
  819. int tz_hour;
  820. int tz_min;
  821. float minSec;
  822. }result;
  823. struct tm tmOrg;
  824. struct tm *tmTarget;
  825. struct timeb tbTarget;
  826. char buf[128];
  827. memset(&result, 0x00, sizeof(struct ParsingResult));
  828. result.result = PASS;
  829. if(strstr((char*)data, ".") != NULL)
  830. {
  831. // Original data with mini second
  832. if(strstr((char*)data, "Z") != NULL)
  833. {
  834. // Original data with Z
  835. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  836. &result.year,
  837. &result.month,
  838. &result.mday,
  839. &result.hour,
  840. &result.min,
  841. &result.sec,
  842. &result.minSec);
  843. }
  844. else
  845. {
  846. // Original data without Z
  847. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  848. &result.year,
  849. &result.month,
  850. &result.mday,
  851. &result.hour,
  852. &result.min,
  853. &result.sec,
  854. &result.minSec,
  855. &result.tz_hour,
  856. &result.tz_min);
  857. }
  858. }
  859. else
  860. {
  861. // Original data without mini second
  862. if(strstr((char*)data, "Z") != NULL)
  863. {
  864. // Original data with Z
  865. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  866. &result.year,
  867. &result.month,
  868. &result.mday,
  869. &result.hour,
  870. &result.min,
  871. &result.sec);
  872. }
  873. else
  874. {
  875. // Original data without Z
  876. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  877. &result.year,
  878. &result.month,
  879. &result.mday,
  880. &result.hour,
  881. &result.min,
  882. &result.sec,
  883. &result.tz_hour,
  884. &result.tz_min);
  885. }
  886. }
  887. tmOrg.tm_year = result.year - 1900;
  888. tmOrg.tm_mon = result.month - 1;
  889. tmOrg.tm_mday = result.mday;
  890. tmOrg.tm_hour = result.hour;
  891. tmOrg.tm_min = result.min;
  892. tmOrg.tm_sec = result.sec;
  893. tmOrg.tm_gmtoff = 0;
  894. tbTarget.time = mktime(&tmOrg);
  895. tbTarget.timezone = 0;
  896. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  897. tmTarget = gmtime(&tbTarget.time);
  898. 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);
  899. //DEBUG_INFO(" org date time: %s\n", data);
  900. //DEBUG_INFO("parse date time: %s\n", buf);
  901. system(buf);
  902. system("/sbin/hwclock -w --systohc");
  903. if(result.scanedElement < 6)
  904. result.result = FAIL;
  905. return result.result;
  906. }
  907. //==========================================
  908. // GetCompositeSchedule logic related function
  909. //==========================================
  910. int DiffTimebSec(struct timeb ST, struct timeb ET)
  911. {
  912. //return milli-second
  913. unsigned int StartTime,StopTime;
  914. StartTime=(unsigned int)ST.time;
  915. StopTime=(unsigned int)ET.time;
  916. return (StopTime-StartTime);
  917. }
  918. int DiffTimebWithNowSec(struct timeb ST)
  919. {
  920. //return milli-second
  921. struct timeb ET;
  922. unsigned int StartTime,StopTime;
  923. ftime(&ET);
  924. StartTime=(unsigned int)ST.time;
  925. StopTime=(unsigned int)ET.time;
  926. return (StopTime-StartTime);
  927. }
  928. int getStartStop(uint8_t *start, uint8_t *stop)
  929. {
  930. struct ParsingResult
  931. {
  932. int result;
  933. int scanedElement;
  934. int year;
  935. int month;
  936. int mday;
  937. int hour;
  938. int min;
  939. int sec;
  940. int tz_hour;
  941. int tz_min;
  942. float minSec;
  943. };
  944. struct ParsingResult parseStart;
  945. struct ParsingResult parseStop;
  946. int result = -1;
  947. struct tm tmStart;
  948. struct timeb tbStart;
  949. struct tm tmStop;
  950. struct timeb tbStop;
  951. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  952. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  953. // Scan start & stop date time
  954. if(strstr((char*)start, ".") != NULL)
  955. {
  956. // Original data with mini second
  957. if(strstr((char*)start, "Z") != NULL)
  958. {
  959. // Original data with Z
  960. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  961. &parseStart.year,
  962. &parseStart.month,
  963. &parseStart.mday,
  964. &parseStart.hour,
  965. &parseStart.min,
  966. &parseStart.sec,
  967. &parseStart.minSec);
  968. }
  969. else
  970. {
  971. // Original data without Z
  972. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  973. &parseStart.year,
  974. &parseStart.month,
  975. &parseStart.mday,
  976. &parseStart.hour,
  977. &parseStart.min,
  978. &parseStart.sec,
  979. &parseStart.minSec,
  980. &parseStart.tz_hour,
  981. &parseStart.tz_min);
  982. }
  983. }
  984. else
  985. {
  986. // Original data without mini second
  987. if(strstr((char*)start, "Z") != NULL)
  988. {
  989. // Original data with Z
  990. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  991. &parseStart.year,
  992. &parseStart.month,
  993. &parseStart.mday,
  994. &parseStart.hour,
  995. &parseStart.min,
  996. &parseStart.sec);
  997. }
  998. else
  999. {
  1000. // Original data without Z
  1001. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1002. &parseStart.year,
  1003. &parseStart.month,
  1004. &parseStart.mday,
  1005. &parseStart.hour,
  1006. &parseStart.min,
  1007. &parseStart.sec,
  1008. &parseStart.tz_hour,
  1009. &parseStart.tz_min);
  1010. }
  1011. }
  1012. if(strstr((char*)stop, ".") != NULL)
  1013. {
  1014. // Original data with mini second
  1015. if(strstr((char*)stop, "Z") != NULL)
  1016. {
  1017. // Original data with Z
  1018. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1019. &parseStop.year,
  1020. &parseStop.month,
  1021. &parseStop.mday,
  1022. &parseStop.hour,
  1023. &parseStop.min,
  1024. &parseStop.sec,
  1025. &parseStop.minSec);
  1026. }
  1027. else
  1028. {
  1029. // Original data without Z
  1030. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1031. &parseStop.year,
  1032. &parseStop.month,
  1033. &parseStop.mday,
  1034. &parseStop.hour,
  1035. &parseStop.min,
  1036. &parseStop.sec,
  1037. &parseStop.minSec,
  1038. &parseStop.tz_hour,
  1039. &parseStop.tz_min);
  1040. }
  1041. }
  1042. else
  1043. {
  1044. // Original data without mini second
  1045. if(strstr((char*)stop, "Z") != NULL)
  1046. {
  1047. // Original data with Z
  1048. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1049. &parseStop.year,
  1050. &parseStop.month,
  1051. &parseStop.mday,
  1052. &parseStop.hour,
  1053. &parseStop.min,
  1054. &parseStop.sec);
  1055. }
  1056. else
  1057. {
  1058. // Original data without Z
  1059. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1060. &parseStop.year,
  1061. &parseStop.month,
  1062. &parseStop.mday,
  1063. &parseStop.hour,
  1064. &parseStop.min,
  1065. &parseStop.sec,
  1066. &parseStop.tz_hour,
  1067. &parseStop.tz_min);
  1068. }
  1069. }
  1070. // Calculate date time difference
  1071. if((parseStart.scanedElement >=6) &&
  1072. (parseStop.scanedElement >=6))
  1073. {
  1074. //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);
  1075. //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);
  1076. tmStart.tm_year = parseStart.year - 1900;
  1077. tmStart.tm_mon = parseStart.month - 1;
  1078. tmStart.tm_mday = parseStart.mday;
  1079. tmStart.tm_hour = parseStart.hour;
  1080. tmStart.tm_min = parseStart.min;
  1081. tmStart.tm_sec = parseStart.sec;
  1082. tmStart.tm_gmtoff = 0;
  1083. tbStart.time = mktime(&tmStart);
  1084. tbStart.timezone = 0;
  1085. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1086. tmStop.tm_year = parseStop.year - 1900;
  1087. tmStop.tm_mon = parseStop.month - 1;
  1088. tmStop.tm_mday = parseStop.mday;
  1089. tmStop.tm_hour = parseStop.hour;
  1090. tmStop.tm_min = parseStop.min;
  1091. tmStop.tm_sec = parseStop.sec;
  1092. tmStop.tm_gmtoff = 0;
  1093. tbStop.time = mktime(&tmStop);
  1094. tbStop.timezone = 0;
  1095. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1096. result = DiffTimebSec(tbStart, tbStop);
  1097. //DEBUG_INFO("getStartStop(): %d\n", result);
  1098. }
  1099. else
  1100. {
  1101. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1102. }
  1103. return result;
  1104. }
  1105. int isOvertNow(uint8_t *start)
  1106. {
  1107. int result = NO;
  1108. struct ParsingResult
  1109. {
  1110. int result;
  1111. int scanedElement;
  1112. int year;
  1113. int month;
  1114. int mday;
  1115. int hour;
  1116. int min;
  1117. int sec;
  1118. int tz_hour;
  1119. int tz_min;
  1120. float minSec;
  1121. }parsingResult;
  1122. struct tm tmStart;
  1123. struct timeb tbStart;
  1124. if(strstr((char*)start, ".") != NULL)
  1125. {
  1126. // Original data with mini second
  1127. if(strstr((char*)start, "Z") != NULL)
  1128. {
  1129. // Original data with Z
  1130. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1131. &parsingResult.year,
  1132. &parsingResult.month,
  1133. &parsingResult.mday,
  1134. &parsingResult.hour,
  1135. &parsingResult.min,
  1136. &parsingResult.sec,
  1137. &parsingResult.minSec);
  1138. }
  1139. else
  1140. {
  1141. // Original data without Z
  1142. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1143. &parsingResult.year,
  1144. &parsingResult.month,
  1145. &parsingResult.mday,
  1146. &parsingResult.hour,
  1147. &parsingResult.min,
  1148. &parsingResult.sec,
  1149. &parsingResult.minSec,
  1150. &parsingResult.tz_hour,
  1151. &parsingResult.tz_min);
  1152. }
  1153. }
  1154. else
  1155. {
  1156. // Original data without mini second
  1157. if(strstr((char*)start, "Z") != NULL)
  1158. {
  1159. // Original data with Z
  1160. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1161. &parsingResult.year,
  1162. &parsingResult.month,
  1163. &parsingResult.mday,
  1164. &parsingResult.hour,
  1165. &parsingResult.min,
  1166. &parsingResult.sec);
  1167. }
  1168. else
  1169. {
  1170. // Original data without Z
  1171. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1172. &parsingResult.year,
  1173. &parsingResult.month,
  1174. &parsingResult.mday,
  1175. &parsingResult.hour,
  1176. &parsingResult.min,
  1177. &parsingResult.sec,
  1178. &parsingResult.tz_hour,
  1179. &parsingResult.tz_min);
  1180. }
  1181. }
  1182. if(parsingResult.scanedElement >= 6)
  1183. {
  1184. tmStart.tm_year = parsingResult.year - 1900;
  1185. tmStart.tm_mon = parsingResult.month - 1;
  1186. tmStart.tm_mday = parsingResult.mday;
  1187. tmStart.tm_hour = parsingResult.hour;
  1188. tmStart.tm_min = parsingResult.min;
  1189. tmStart.tm_sec = parsingResult.sec;
  1190. tmStart.tm_gmtoff = 0;
  1191. tbStart.time = mktime(&tmStart);
  1192. tbStart.timezone = 0;
  1193. tbStart.millitm = 0;
  1194. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1195. if(DiffTimebWithNowSec(tbStart) <= 0)
  1196. result = NO;
  1197. else
  1198. result = YES;
  1199. }
  1200. else
  1201. {
  1202. DEBUG_WARN("Start date parsing error.\n");
  1203. }
  1204. return result;
  1205. }
  1206. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1207. {
  1208. struct ParsingResult
  1209. {
  1210. int result;
  1211. int scanedElement;
  1212. int year;
  1213. int month;
  1214. int mday;
  1215. int hour;
  1216. int min;
  1217. int sec;
  1218. int tz_hour;
  1219. int tz_min;
  1220. float minSec;
  1221. };
  1222. struct ParsingResult parseStart;
  1223. struct ParsingResult parseStop;
  1224. int result = -1;
  1225. struct tm tmStart;
  1226. struct timeb tbStart;
  1227. struct tm tmStop;
  1228. struct timeb tbStop;
  1229. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1230. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1231. // Scan start & stop date time
  1232. if(strstr((char*)start, ".") != NULL)
  1233. {
  1234. // Original data with mini second
  1235. if(strstr((char*)start, "Z") != NULL)
  1236. {
  1237. // Original data with Z
  1238. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1239. &parseStart.year,
  1240. &parseStart.month,
  1241. &parseStart.mday,
  1242. &parseStart.hour,
  1243. &parseStart.min,
  1244. &parseStart.sec,
  1245. &parseStart.minSec);
  1246. }
  1247. else
  1248. {
  1249. // Original data without Z
  1250. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1251. &parseStart.year,
  1252. &parseStart.month,
  1253. &parseStart.mday,
  1254. &parseStart.hour,
  1255. &parseStart.min,
  1256. &parseStart.sec,
  1257. &parseStart.minSec,
  1258. &parseStart.tz_hour,
  1259. &parseStart.tz_min);
  1260. }
  1261. }
  1262. else
  1263. {
  1264. // Original data without mini second
  1265. if(strstr((char*)start, "Z") != NULL)
  1266. {
  1267. // Original data with Z
  1268. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1269. &parseStart.year,
  1270. &parseStart.month,
  1271. &parseStart.mday,
  1272. &parseStart.hour,
  1273. &parseStart.min,
  1274. &parseStart.sec);
  1275. }
  1276. else
  1277. {
  1278. // Original data without Z
  1279. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1280. &parseStart.year,
  1281. &parseStart.month,
  1282. &parseStart.mday,
  1283. &parseStart.hour,
  1284. &parseStart.min,
  1285. &parseStart.sec,
  1286. &parseStart.tz_hour,
  1287. &parseStart.tz_min);
  1288. }
  1289. }
  1290. if(strstr((char*)stop, ".") != NULL)
  1291. {
  1292. // Original data with mini second
  1293. if(strstr((char*)stop, "Z") != NULL)
  1294. {
  1295. // Original data with Z
  1296. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1297. &parseStop.year,
  1298. &parseStop.month,
  1299. &parseStop.mday,
  1300. &parseStop.hour,
  1301. &parseStop.min,
  1302. &parseStop.sec,
  1303. &parseStop.minSec);
  1304. }
  1305. else
  1306. {
  1307. // Original data without Z
  1308. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1309. &parseStop.year,
  1310. &parseStop.month,
  1311. &parseStop.mday,
  1312. &parseStop.hour,
  1313. &parseStop.min,
  1314. &parseStop.sec,
  1315. &parseStop.minSec,
  1316. &parseStop.tz_hour,
  1317. &parseStop.tz_min);
  1318. }
  1319. }
  1320. else
  1321. {
  1322. // Original data without mini second
  1323. if(strstr((char*)stop, "Z") != NULL)
  1324. {
  1325. // Original data with Z
  1326. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1327. &parseStop.year,
  1328. &parseStop.month,
  1329. &parseStop.mday,
  1330. &parseStop.hour,
  1331. &parseStop.min,
  1332. &parseStop.sec);
  1333. }
  1334. else
  1335. {
  1336. // Original data without Z
  1337. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1338. &parseStop.year,
  1339. &parseStop.month,
  1340. &parseStop.mday,
  1341. &parseStop.hour,
  1342. &parseStop.min,
  1343. &parseStop.sec,
  1344. &parseStop.tz_hour,
  1345. &parseStop.tz_min);
  1346. }
  1347. }
  1348. // Calculate date time difference
  1349. if((parseStart.scanedElement >=6) &&
  1350. (parseStop.scanedElement >=6))
  1351. {
  1352. //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);
  1353. //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);
  1354. tmStart.tm_year = parseStart.year - 1900;
  1355. tmStart.tm_mon = parseStart.month - 1;
  1356. tmStart.tm_mday = parseStart.mday;
  1357. tmStart.tm_hour = parseStart.hour;
  1358. tmStart.tm_min = parseStart.min;
  1359. tmStart.tm_sec = parseStart.sec;
  1360. tmStart.tm_gmtoff = 0;
  1361. tbStart.time = mktime(&tmStart);
  1362. tbStart.timezone = 0;
  1363. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1364. tmStop.tm_year = parseStop.year - 1900;
  1365. tmStop.tm_mon = parseStop.month - 1;
  1366. tmStop.tm_mday = parseStop.mday;
  1367. tmStop.tm_hour = parseStop.hour;
  1368. tmStop.tm_min = parseStop.min;
  1369. tmStop.tm_sec = parseStop.sec;
  1370. tmStop.tm_gmtoff = 0;
  1371. tbStop.time = mktime(&tmStop);
  1372. tbStop.timezone = 0;
  1373. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1374. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1375. //DEBUG_INFO("getStartStop(): %d\n", result);
  1376. }
  1377. else
  1378. {
  1379. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1380. }
  1381. return result;
  1382. }
  1383. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1384. {
  1385. FILE *fp;
  1386. char profileFileName[128];
  1387. char *line = NULL;
  1388. size_t len = 0;
  1389. time_t CurrentTime;
  1390. struct tm *tmComposite;
  1391. struct StructChargingProfile maxProfile;
  1392. struct StructChargingProfile compositeProfile;
  1393. uint8_t limitMax=0;
  1394. int compositePeriodIdx = 0;
  1395. //uint8_t isDurationNull = FALSE;
  1396. CurrentTime = time(NULL);
  1397. tmComposite=localtime(&CurrentTime);
  1398. 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);
  1399. if(isUnitA)
  1400. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1401. else
  1402. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1403. compositeProfile.ChargingSchedule.Duration = durationReq;
  1404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1405. {
  1406. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1407. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1408. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1409. }
  1410. compositeProfile.ChargingProfileId = 0;
  1411. compositeProfile.StackLevel = 99 ;
  1412. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1413. maxProfile.ChargingProfileId = -1;
  1414. maxProfile.ChargingSchedule.Duration = -1;
  1415. system("rm -f /tmp/*.json");
  1416. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1417. // Search max profile
  1418. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1419. if((access(profileFileName, F_OK))!=-1)
  1420. {
  1421. fp = fopen(profileFileName, "r");
  1422. while(getline(&line, &len, fp) != -1)
  1423. {
  1424. json_object *obj = NULL;
  1425. obj = json_tokener_parse(line);
  1426. if(is_error(obj))
  1427. {
  1428. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1429. }
  1430. else
  1431. {
  1432. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1433. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1434. )
  1435. {
  1436. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1437. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1438. )
  1439. {
  1440. struct tm tmFrom, tmTo;
  1441. struct timeb tbFrom, tbTo;
  1442. 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) &&
  1443. (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))
  1444. {
  1445. tmFrom.tm_year -= 1900;
  1446. tmFrom.tm_mon -= 1;
  1447. tbFrom.time = mktime(&tmFrom);
  1448. tmTo.tm_year -= 1900;
  1449. tmTo.tm_mon -= 1;
  1450. tbTo.time = mktime(&tmTo);
  1451. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1452. {
  1453. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1454. {
  1455. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1456. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1457. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1458. }
  1459. if(maxProfile.ChargingProfileId == -1)
  1460. DEBUG_INFO("MaxProfile found.\n");
  1461. else
  1462. DEBUG_INFO("MaxProfile updated.\n");
  1463. // Required item
  1464. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1465. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1466. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1467. if(isUnitA)
  1468. {
  1469. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1470. 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++)
  1471. {
  1472. 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"));
  1473. 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?
  1474. 3:
  1475. 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")));
  1476. 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")));
  1477. }
  1478. }
  1479. else
  1480. {
  1481. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1482. 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++)
  1483. {
  1484. 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"));
  1485. 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?
  1486. 3:
  1487. 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")));
  1488. 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));
  1489. }
  1490. }
  1491. // Optional item
  1492. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1493. {
  1494. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1495. }
  1496. else
  1497. {
  1498. sprintf((char*)maxProfile.ValidFrom, " ");
  1499. }
  1500. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1501. {
  1502. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1503. }
  1504. else
  1505. {
  1506. sprintf((char*)maxProfile.ValidTo, " ");
  1507. }
  1508. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1509. {
  1510. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1511. }
  1512. else
  1513. {
  1514. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1515. }
  1516. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1517. {
  1518. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1519. }
  1520. else
  1521. {
  1522. maxProfile.TransactionId = -1;
  1523. }
  1524. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1525. {
  1526. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1527. }
  1528. else
  1529. {
  1530. maxProfile.ChargingSchedule.Duration = 86400;
  1531. //isDurationNull = TRUE;
  1532. }
  1533. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1534. {
  1535. 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")));
  1536. }
  1537. else
  1538. {
  1539. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1540. }
  1541. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1542. {
  1543. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1544. }
  1545. else
  1546. {
  1547. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1548. }
  1549. }
  1550. }
  1551. }
  1552. else
  1553. {
  1554. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1555. {
  1556. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1557. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1558. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1559. }
  1560. if(maxProfile.ChargingProfileId == -1)
  1561. DEBUG_INFO("MaxProfile found.\n");
  1562. else
  1563. DEBUG_INFO("MaxProfile updated.\n");
  1564. // Required item
  1565. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1566. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1567. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1568. if(isUnitA)
  1569. {
  1570. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1571. 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++)
  1572. {
  1573. 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"));
  1574. 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?
  1575. 3:
  1576. 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")));
  1577. 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")));
  1578. }
  1579. }
  1580. else
  1581. {
  1582. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1583. 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++)
  1584. {
  1585. 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"));
  1586. 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?
  1587. 3:
  1588. 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")));
  1589. 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));
  1590. }
  1591. }
  1592. // Optional item
  1593. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1594. {
  1595. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1596. }
  1597. else
  1598. {
  1599. sprintf((char*)maxProfile.ValidFrom, " ");
  1600. }
  1601. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1602. {
  1603. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1604. }
  1605. else
  1606. {
  1607. sprintf((char*)maxProfile.ValidTo, " ");
  1608. }
  1609. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1610. {
  1611. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1612. }
  1613. else
  1614. {
  1615. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1616. }
  1617. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1618. {
  1619. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1620. }
  1621. else
  1622. {
  1623. maxProfile.TransactionId = -1;
  1624. }
  1625. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1626. {
  1627. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1628. }
  1629. else
  1630. {
  1631. maxProfile.ChargingSchedule.Duration = 86400;
  1632. //isDurationNull = TRUE;
  1633. }
  1634. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1635. {
  1636. 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")));
  1637. }
  1638. else
  1639. {
  1640. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1641. }
  1642. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1643. {
  1644. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1645. }
  1646. else
  1647. {
  1648. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1649. }
  1650. }
  1651. }
  1652. }
  1653. json_object_put(obj);
  1654. }
  1655. fclose(fp);
  1656. /*
  1657. if(maxProfile.ChargingProfileId !=-1)
  1658. {
  1659. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1660. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1661. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1662. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1663. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1664. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1665. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1666. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1667. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1668. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1669. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1670. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1671. {
  1672. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1673. {
  1674. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1675. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1676. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1677. }
  1678. }
  1679. }
  1680. else
  1681. DEBUG_INFO("MaxProfile not found.\n");
  1682. DEBUG_INFO("------------------------------------\n");*/
  1683. }
  1684. if(maxProfile.ChargingProfileId != -1)
  1685. {
  1686. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1687. {
  1688. if(maxProfile.ChargingSchedule.Duration != -1)
  1689. {
  1690. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1691. 0:
  1692. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1693. }
  1694. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1695. {
  1696. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1697. {
  1698. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1699. 0:
  1700. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1701. if(idxPeriod > 0)
  1702. {
  1703. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1704. {
  1705. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1706. }
  1707. }
  1708. }
  1709. }
  1710. }
  1711. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1712. {
  1713. if(maxProfile.ChargingSchedule.Duration != -1)
  1714. {
  1715. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1716. }
  1717. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1718. {
  1719. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1720. {
  1721. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1722. if(idxPeriod > 0)
  1723. {
  1724. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1725. {
  1726. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1727. }
  1728. }
  1729. }
  1730. }
  1731. }
  1732. else
  1733. {
  1734. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1735. {
  1736. if(maxProfile.ChargingSchedule.Duration != -1)
  1737. {
  1738. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1739. 0:
  1740. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1741. }
  1742. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1743. {
  1744. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1745. {
  1746. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1747. 0:
  1748. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1749. if(idxPeriod > 0)
  1750. {
  1751. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1752. {
  1753. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1754. }
  1755. }
  1756. }
  1757. }
  1758. }
  1759. else
  1760. {
  1761. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  1762. {
  1763. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1764. 0:
  1765. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1766. }
  1767. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1768. {
  1769. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1770. {
  1771. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1772. 0:
  1773. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1774. if(idxPeriod > 0)
  1775. {
  1776. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1777. {
  1778. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1779. }
  1780. }
  1781. }
  1782. }
  1783. }
  1784. }
  1785. /*
  1786. DEBUG_INFO("MaxProfile after align.\n");
  1787. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1788. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1789. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1790. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1791. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1792. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1793. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1794. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1795. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1796. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1797. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1798. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1799. {
  1800. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1801. {
  1802. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1803. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1804. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1805. }
  1806. }
  1807. DEBUG_INFO("------------------------------------\n");*/
  1808. }
  1809. // Find each profile period quantity
  1810. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1811. {
  1812. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1813. limitMax = idx+1;
  1814. }
  1815. if(maxProfile.ChargingProfileId != -1)
  1816. {
  1817. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1818. {
  1819. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1820. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1821. (maxProfile.ChargingSchedule.Duration > 0))
  1822. {
  1823. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1824. {
  1825. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1826. compositePeriodIdx++;
  1827. }
  1828. else
  1829. {
  1830. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1831. }
  1832. }
  1833. }
  1834. }
  1835. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1836. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1837. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1838. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1839. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1840. {
  1841. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1842. {
  1843. compositeProfile.ChargingProfileId = 1;
  1844. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1845. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1846. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1847. }
  1848. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1849. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1850. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1851. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1852. }
  1853. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1854. if(line)
  1855. free(line);
  1856. }
  1857. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1858. {
  1859. FILE *fp;
  1860. char profileFileName[128];
  1861. char *line = NULL;
  1862. size_t len = 0;
  1863. time_t CurrentTime;
  1864. struct tm *tmComposite;
  1865. struct StructChargingProfile maxProfile;
  1866. struct StructChargingProfile defaultTxProfile;
  1867. struct StructChargingProfile txProfile;
  1868. struct StructChargingProfile compositeProfile;
  1869. struct StructChargingSchedulePeriod tmpPeriod;
  1870. uint8_t limitMax=0;
  1871. uint8_t limitDef=0;
  1872. uint8_t limitTx=0;
  1873. int compositePeriodIdx = 0;
  1874. CurrentTime = time(NULL);
  1875. tmComposite=localtime(&CurrentTime);
  1876. 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);
  1877. if(isUnitA)
  1878. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1879. else
  1880. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1881. compositeProfile.ChargingSchedule.Duration = durationReq;
  1882. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1883. {
  1884. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1885. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1886. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1887. }
  1888. compositeProfile.ChargingProfileId = 0;
  1889. compositeProfile.StackLevel = 99 ;
  1890. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1891. maxProfile.ChargingProfileId = -1;
  1892. defaultTxProfile.ChargingProfileId = -1;
  1893. txProfile.ChargingProfileId = -1;
  1894. maxProfile.ChargingSchedule.Duration = -1;
  1895. defaultTxProfile.ChargingSchedule.Duration = -1;
  1896. txProfile.ChargingSchedule.Duration = -1;
  1897. system("rm -f /tmp/*.json");
  1898. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1899. /*
  1900. * Search valid charging profile
  1901. */
  1902. //DEBUG_INFO("====================================\n");
  1903. // Search tx profile
  1904. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1905. if((access(profileFileName, F_OK))!=-1)
  1906. {
  1907. fp = fopen(profileFileName, "r");
  1908. while(getline(&line, &len, fp) != -1)
  1909. {
  1910. json_object *obj = NULL;
  1911. obj = json_tokener_parse(line);
  1912. if(is_error(obj))
  1913. {
  1914. DEBUG_ERROR("Parse txProfile from file error.\n");
  1915. }
  1916. else
  1917. {
  1918. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1919. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1920. )
  1921. {
  1922. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1923. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1924. )
  1925. {
  1926. struct tm tmFrom, tmTo;
  1927. struct timeb tbFrom, tbTo;
  1928. 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) &&
  1929. (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))
  1930. {
  1931. tmFrom.tm_year -= 1900;
  1932. tmFrom.tm_mon -= 1;
  1933. tbFrom.time = mktime(&tmFrom);
  1934. tmTo.tm_year -= 1900;
  1935. tmTo.tm_mon -= 1;
  1936. tbTo.time = mktime(&tmTo);
  1937. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1938. {
  1939. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1940. {
  1941. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1942. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1943. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1944. }
  1945. if(txProfile.ChargingProfileId == -1)
  1946. DEBUG_INFO("TxProfile found.\n");
  1947. else
  1948. DEBUG_INFO("TxProfile updated.\n");
  1949. // Required item
  1950. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1951. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1952. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1953. if(isUnitA)
  1954. {
  1955. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1956. 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++)
  1957. {
  1958. 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"));
  1959. 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?
  1960. 3:
  1961. 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")));
  1962. 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")));
  1963. }
  1964. }
  1965. else
  1966. {
  1967. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1968. 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++)
  1969. {
  1970. 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"));
  1971. 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?
  1972. 3:
  1973. 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")));
  1974. 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));
  1975. }
  1976. }
  1977. // Optional item
  1978. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1979. {
  1980. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1981. }
  1982. else
  1983. {
  1984. sprintf((char*)txProfile.ValidFrom, " ");
  1985. }
  1986. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1987. {
  1988. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1989. }
  1990. else
  1991. {
  1992. sprintf((char*)txProfile.ValidTo, " ");
  1993. }
  1994. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1995. {
  1996. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1997. }
  1998. else
  1999. {
  2000. sprintf((char*)txProfile.RecurrencyKind, " ");
  2001. }
  2002. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2003. {
  2004. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2005. }
  2006. else
  2007. {
  2008. txProfile.TransactionId = -1;
  2009. }
  2010. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2011. {
  2012. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2013. }
  2014. else
  2015. {
  2016. txProfile.ChargingSchedule.Duration = 86400;
  2017. }
  2018. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2019. {
  2020. 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")));
  2021. }
  2022. else
  2023. {
  2024. 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));
  2025. }
  2026. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2027. {
  2028. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2029. }
  2030. else
  2031. {
  2032. txProfile.ChargingSchedule.MinChargingRate = -1;
  2033. }
  2034. }
  2035. }
  2036. }
  2037. else
  2038. {
  2039. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2040. {
  2041. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2042. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2043. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2044. }
  2045. if(txProfile.ChargingProfileId == -1)
  2046. DEBUG_INFO("TxProfile found.\n");
  2047. else
  2048. DEBUG_INFO("TxProfile updated.\n");
  2049. // Required item
  2050. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2051. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2052. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2053. if(isUnitA)
  2054. {
  2055. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2056. 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++)
  2057. {
  2058. 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"));
  2059. 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?
  2060. 3:
  2061. 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")));
  2062. 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")));
  2063. }
  2064. }
  2065. else
  2066. {
  2067. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2068. 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++)
  2069. {
  2070. 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"));
  2071. 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?
  2072. 3:
  2073. 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")));
  2074. 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));
  2075. }
  2076. }
  2077. // Optional item
  2078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2079. {
  2080. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2081. }
  2082. else
  2083. {
  2084. sprintf((char*)txProfile.ValidFrom, " ");
  2085. }
  2086. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2087. {
  2088. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2089. }
  2090. else
  2091. {
  2092. sprintf((char*)txProfile.ValidTo, " ");
  2093. }
  2094. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2095. {
  2096. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2097. }
  2098. else
  2099. {
  2100. sprintf((char*)txProfile.RecurrencyKind, " ");
  2101. }
  2102. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2103. {
  2104. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2105. }
  2106. else
  2107. {
  2108. txProfile.TransactionId = -1;
  2109. }
  2110. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2111. {
  2112. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2113. }
  2114. else
  2115. {
  2116. txProfile.ChargingSchedule.Duration = 86400;
  2117. }
  2118. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2119. {
  2120. 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")));
  2121. }
  2122. else
  2123. {
  2124. 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));
  2125. }
  2126. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2127. {
  2128. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2129. }
  2130. else
  2131. {
  2132. txProfile.ChargingSchedule.MinChargingRate = -1;
  2133. }
  2134. }
  2135. }
  2136. }
  2137. json_object_put(obj);
  2138. }
  2139. fclose(fp);
  2140. /*
  2141. if(txProfile.ChargingProfileId != -1)
  2142. {
  2143. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2144. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2145. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2146. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2147. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2148. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2149. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2150. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2151. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2152. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2153. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2154. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2155. {
  2156. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2157. {
  2158. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2159. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2160. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2161. }
  2162. }
  2163. }
  2164. else
  2165. DEBUG_INFO("TxProfile not found.\n");*/
  2166. }
  2167. // Search default tx profile
  2168. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2169. if((access(profileFileName, F_OK))==-1)
  2170. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2171. if((access(profileFileName, F_OK))!=-1)
  2172. {
  2173. fp = fopen(profileFileName, "r");
  2174. while(getline(&line, &len, fp) != -1)
  2175. {
  2176. json_object *obj = NULL;
  2177. obj = json_tokener_parse(line);
  2178. if(is_error(obj))
  2179. {
  2180. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2181. }
  2182. else
  2183. {
  2184. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2185. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2186. )
  2187. {
  2188. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2189. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2190. )
  2191. {
  2192. struct tm tmFrom, tmTo;
  2193. struct timeb tbFrom, tbTo;
  2194. 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) &&
  2195. (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))
  2196. {
  2197. tmFrom.tm_year -= 1900;
  2198. tmFrom.tm_mon -= 1;
  2199. tbFrom.time = mktime(&tmFrom);
  2200. tmTo.tm_year -= 1900;
  2201. tmTo.tm_mon -= 1;
  2202. tbTo.time = mktime(&tmTo);
  2203. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2204. {
  2205. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2206. {
  2207. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2208. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2209. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2210. }
  2211. if(defaultTxProfile.ChargingProfileId == -1)
  2212. DEBUG_INFO("TxDefaultProfile found.\n");
  2213. else
  2214. DEBUG_INFO("TxDefaultProfile updated.\n");
  2215. // Required item
  2216. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2217. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2218. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2219. if(isUnitA)
  2220. {
  2221. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2222. 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++)
  2223. {
  2224. 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"));
  2225. 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?
  2226. 3:
  2227. 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")));
  2228. 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")));
  2229. }
  2230. }
  2231. else
  2232. {
  2233. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2234. 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++)
  2235. {
  2236. 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"));
  2237. 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?
  2238. 3:
  2239. 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")));
  2240. 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));
  2241. }
  2242. }
  2243. // Optional item
  2244. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2245. {
  2246. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2247. }
  2248. else
  2249. {
  2250. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2251. }
  2252. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2253. {
  2254. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2255. }
  2256. else
  2257. {
  2258. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2259. }
  2260. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2261. {
  2262. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2263. }
  2264. else
  2265. {
  2266. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2267. }
  2268. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2269. {
  2270. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2271. }
  2272. else
  2273. {
  2274. defaultTxProfile.TransactionId = -1;
  2275. }
  2276. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2277. {
  2278. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2279. }
  2280. else
  2281. {
  2282. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2283. }
  2284. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2285. {
  2286. 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")));
  2287. }
  2288. else
  2289. {
  2290. 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));
  2291. }
  2292. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2293. {
  2294. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2295. }
  2296. else
  2297. {
  2298. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2299. }
  2300. }
  2301. }
  2302. }
  2303. else
  2304. {
  2305. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2306. {
  2307. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2308. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2309. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2310. }
  2311. if(defaultTxProfile.ChargingProfileId == -1)
  2312. DEBUG_INFO("TxDefaultProfile found.\n");
  2313. else
  2314. DEBUG_INFO("TxDefaultProfile updated.\n");
  2315. // Required item
  2316. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2317. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2318. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2319. if(isUnitA)
  2320. {
  2321. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2322. 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++)
  2323. {
  2324. 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"));
  2325. 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?
  2326. 3:
  2327. 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")));
  2328. 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")));
  2329. }
  2330. }
  2331. else
  2332. {
  2333. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2334. 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++)
  2335. {
  2336. 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"));
  2337. 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?
  2338. 3:
  2339. 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")));
  2340. 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));
  2341. }
  2342. }
  2343. // Optional item
  2344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2345. {
  2346. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2347. }
  2348. else
  2349. {
  2350. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2351. }
  2352. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2353. {
  2354. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2355. }
  2356. else
  2357. {
  2358. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2359. }
  2360. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2361. {
  2362. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2363. }
  2364. else
  2365. {
  2366. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2367. }
  2368. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2369. {
  2370. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2371. }
  2372. else
  2373. {
  2374. defaultTxProfile.TransactionId = -1;
  2375. }
  2376. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2377. {
  2378. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2379. }
  2380. else
  2381. {
  2382. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2383. }
  2384. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2385. {
  2386. 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")));
  2387. }
  2388. else
  2389. {
  2390. 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));
  2391. }
  2392. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2393. {
  2394. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2395. }
  2396. else
  2397. {
  2398. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2399. }
  2400. }
  2401. }
  2402. }
  2403. json_object_put(obj);
  2404. }
  2405. fclose(fp);
  2406. /*
  2407. if(defaultTxProfile.ChargingProfileId != -1)
  2408. {
  2409. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2410. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2411. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2412. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2413. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2414. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2415. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2416. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2417. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2418. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2419. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2420. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2421. {
  2422. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2423. {
  2424. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2425. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2426. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2427. }
  2428. }
  2429. }
  2430. else
  2431. DEBUG_INFO("TxDefaultProfile not found.\n");
  2432. DEBUG_INFO("------------------------------------\n");*/
  2433. }
  2434. // Search max profile
  2435. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2436. if((access(profileFileName, F_OK))!=-1)
  2437. {
  2438. fp = fopen(profileFileName, "r");
  2439. while(getline(&line, &len, fp) != -1)
  2440. {
  2441. json_object *obj = NULL;
  2442. obj = json_tokener_parse(line);
  2443. if(is_error(obj))
  2444. {
  2445. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2446. }
  2447. else
  2448. {
  2449. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2450. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2451. )
  2452. {
  2453. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2454. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2455. )
  2456. {
  2457. struct tm tmFrom, tmTo;
  2458. struct timeb tbFrom, tbTo;
  2459. 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) &&
  2460. (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))
  2461. {
  2462. tmFrom.tm_year -= 1900;
  2463. tmFrom.tm_mon -= 1;
  2464. tbFrom.time = mktime(&tmFrom);
  2465. tmTo.tm_year -= 1900;
  2466. tmTo.tm_mon -= 1;
  2467. tbTo.time = mktime(&tmTo);
  2468. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2469. {
  2470. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2471. {
  2472. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2473. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2474. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2475. }
  2476. if(maxProfile.ChargingProfileId == -1)
  2477. DEBUG_INFO("MaxProfile found.\n");
  2478. else
  2479. DEBUG_INFO("MaxProfile updated.\n");
  2480. // Required item
  2481. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2482. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2483. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2484. if(isUnitA)
  2485. {
  2486. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2487. 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++)
  2488. {
  2489. 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"));
  2490. 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?
  2491. 3:
  2492. 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")));
  2493. 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")));
  2494. }
  2495. }
  2496. else
  2497. {
  2498. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2499. 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++)
  2500. {
  2501. 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"));
  2502. 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?
  2503. 3:
  2504. 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")));
  2505. 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));
  2506. }
  2507. }
  2508. // Optional item
  2509. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2510. {
  2511. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2512. }
  2513. else
  2514. {
  2515. sprintf((char*)maxProfile.ValidFrom, " ");
  2516. }
  2517. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2518. {
  2519. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2520. }
  2521. else
  2522. {
  2523. sprintf((char*)maxProfile.ValidTo, " ");
  2524. }
  2525. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2526. {
  2527. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2528. }
  2529. else
  2530. {
  2531. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2532. }
  2533. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2534. {
  2535. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2536. }
  2537. else
  2538. {
  2539. maxProfile.TransactionId = -1;
  2540. }
  2541. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2542. {
  2543. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2544. }
  2545. else
  2546. {
  2547. maxProfile.ChargingSchedule.Duration = 86400;
  2548. }
  2549. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2550. {
  2551. 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")));
  2552. }
  2553. else
  2554. {
  2555. 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));
  2556. }
  2557. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2558. {
  2559. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2560. }
  2561. else
  2562. {
  2563. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2564. }
  2565. }
  2566. }
  2567. }
  2568. else
  2569. {
  2570. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2571. {
  2572. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2575. }
  2576. if(maxProfile.ChargingProfileId == -1)
  2577. DEBUG_INFO("MaxProfile found.\n");
  2578. else
  2579. DEBUG_INFO("MaxProfile updated.\n");
  2580. // Required item
  2581. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2582. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2583. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2584. if(isUnitA)
  2585. {
  2586. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2587. 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++)
  2588. {
  2589. 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"));
  2590. 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?
  2591. 3:
  2592. 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")));
  2593. 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")));
  2594. }
  2595. }
  2596. else
  2597. {
  2598. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2599. 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++)
  2600. {
  2601. 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"));
  2602. 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?
  2603. 3:
  2604. 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")));
  2605. 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));
  2606. }
  2607. }
  2608. // Optional item
  2609. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2610. {
  2611. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2612. }
  2613. else
  2614. {
  2615. sprintf((char*)maxProfile.ValidFrom, " ");
  2616. }
  2617. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2618. {
  2619. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2620. }
  2621. else
  2622. {
  2623. sprintf((char*)maxProfile.ValidTo, " ");
  2624. }
  2625. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2626. {
  2627. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2628. }
  2629. else
  2630. {
  2631. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2632. }
  2633. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2634. {
  2635. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2636. }
  2637. else
  2638. {
  2639. maxProfile.TransactionId = -1;
  2640. }
  2641. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2642. {
  2643. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2644. }
  2645. else
  2646. {
  2647. maxProfile.ChargingSchedule.Duration = 86400;
  2648. }
  2649. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2650. {
  2651. 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")));
  2652. }
  2653. else
  2654. {
  2655. 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));
  2656. }
  2657. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2658. {
  2659. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2660. }
  2661. else
  2662. {
  2663. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2664. }
  2665. }
  2666. }
  2667. }
  2668. json_object_put(obj);
  2669. }
  2670. fclose(fp);
  2671. /*
  2672. if(maxProfile.ChargingProfileId !=-1)
  2673. {
  2674. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2675. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2676. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2677. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2678. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2679. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2680. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2681. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2682. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2683. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2684. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2685. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2686. {
  2687. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2688. {
  2689. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2690. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2691. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2692. }
  2693. }
  2694. }
  2695. else
  2696. DEBUG_INFO("MaxProfile not found.\n");
  2697. DEBUG_INFO("------------------------------------\n");*/
  2698. }
  2699. /*
  2700. * Align found profile start schedule & periods
  2701. */
  2702. //DEBUG_INFO("====================================\n");
  2703. /*
  2704. // For local test usage, force modify found profile start schedule info
  2705. 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);
  2706. 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);
  2707. 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);
  2708. */
  2709. if(txProfile.ChargingProfileId != -1)
  2710. {
  2711. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2712. {
  2713. if(txProfile.ChargingSchedule.Duration != -1)
  2714. {
  2715. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2716. 0:
  2717. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2718. }
  2719. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2720. {
  2721. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2722. {
  2723. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2724. 0:
  2725. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2726. if(idxPeriod > 0)
  2727. {
  2728. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2729. {
  2730. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2731. }
  2732. }
  2733. }
  2734. }
  2735. }
  2736. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2737. {
  2738. if(txProfile.ChargingSchedule.Duration != -1)
  2739. {
  2740. 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?
  2741. 0:
  2742. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2743. }
  2744. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2745. {
  2746. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2747. {
  2748. 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?
  2749. 0:
  2750. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2751. if(idxPeriod > 0)
  2752. {
  2753. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2754. {
  2755. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2756. }
  2757. }
  2758. }
  2759. }
  2760. }
  2761. else
  2762. {
  2763. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2764. {
  2765. if(txProfile.ChargingSchedule.Duration != -1)
  2766. {
  2767. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2768. 0:
  2769. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2770. }
  2771. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2772. {
  2773. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2774. {
  2775. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2776. 0:
  2777. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2778. if(idxPeriod > 0)
  2779. {
  2780. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2781. {
  2782. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2783. }
  2784. }
  2785. }
  2786. }
  2787. }
  2788. else
  2789. {
  2790. if(txProfile.ChargingSchedule.Duration != -1)
  2791. {
  2792. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2793. 0:
  2794. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2795. }
  2796. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2797. {
  2798. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2799. {
  2800. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2801. 0:
  2802. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2803. if(idxPeriod > 0)
  2804. {
  2805. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2806. {
  2807. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2808. }
  2809. }
  2810. }
  2811. }
  2812. }
  2813. }
  2814. /*
  2815. DEBUG_INFO("txProfile after align.\n");
  2816. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2817. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2818. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2819. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2820. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2821. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2822. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2823. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2824. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2825. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2826. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2827. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2828. {
  2829. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2830. {
  2831. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2832. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2833. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2834. }
  2835. }*/
  2836. }
  2837. if(defaultTxProfile.ChargingProfileId != -1)
  2838. {
  2839. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2840. {
  2841. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2842. {
  2843. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2844. 0:
  2845. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2846. }
  2847. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2848. {
  2849. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2850. {
  2851. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2852. 0:
  2853. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2854. if(idxPeriod > 0)
  2855. {
  2856. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2857. {
  2858. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2859. }
  2860. }
  2861. }
  2862. }
  2863. }
  2864. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2865. {
  2866. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2867. {
  2868. 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?
  2869. 0:
  2870. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2871. }
  2872. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2873. {
  2874. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2875. {
  2876. 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?
  2877. 0:
  2878. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2879. if(idxPeriod > 0)
  2880. {
  2881. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2882. {
  2883. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2884. }
  2885. }
  2886. }
  2887. }
  2888. }
  2889. else
  2890. {
  2891. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2892. {
  2893. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2894. {
  2895. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2896. 0:
  2897. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2898. }
  2899. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2900. {
  2901. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2902. {
  2903. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2904. 0:
  2905. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2906. if(idxPeriod > 0)
  2907. {
  2908. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2909. {
  2910. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2911. }
  2912. }
  2913. }
  2914. }
  2915. }
  2916. else
  2917. {
  2918. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2919. {
  2920. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2921. 0:
  2922. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2923. }
  2924. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2925. {
  2926. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2927. {
  2928. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2929. 0:
  2930. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2931. if(idxPeriod > 0)
  2932. {
  2933. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2934. {
  2935. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2936. }
  2937. }
  2938. }
  2939. }
  2940. }
  2941. }
  2942. /*
  2943. DEBUG_INFO("defaultTxProfile after align.\n");
  2944. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2945. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2946. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2947. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2948. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2949. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2950. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2951. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2952. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2953. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2954. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2955. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2956. {
  2957. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2958. {
  2959. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2960. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2961. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2962. }
  2963. }
  2964. DEBUG_INFO("------------------------------------\n");*/
  2965. }
  2966. if(maxProfile.ChargingProfileId != -1)
  2967. {
  2968. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2969. {
  2970. if(maxProfile.ChargingSchedule.Duration != -1)
  2971. {
  2972. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2973. 0:
  2974. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2975. }
  2976. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2977. {
  2978. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2979. {
  2980. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2981. 0:
  2982. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2983. if(idxPeriod > 0)
  2984. {
  2985. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2986. {
  2987. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2988. }
  2989. }
  2990. }
  2991. }
  2992. }
  2993. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2994. {
  2995. if(maxProfile.ChargingSchedule.Duration != -1)
  2996. {
  2997. 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?
  2998. 0:
  2999. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3000. }
  3001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3002. {
  3003. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3004. {
  3005. 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?
  3006. 0:
  3007. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3008. if(idxPeriod > 0)
  3009. {
  3010. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3011. {
  3012. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3013. }
  3014. }
  3015. }
  3016. }
  3017. }
  3018. else
  3019. {
  3020. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3021. {
  3022. if(maxProfile.ChargingSchedule.Duration != -1)
  3023. {
  3024. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3025. 0:
  3026. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3027. }
  3028. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3029. {
  3030. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3031. {
  3032. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3033. 0:
  3034. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3035. if(idxPeriod > 0)
  3036. {
  3037. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3038. {
  3039. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3040. }
  3041. }
  3042. }
  3043. }
  3044. }
  3045. else
  3046. {
  3047. if(maxProfile.ChargingSchedule.Duration != -1)
  3048. {
  3049. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3050. 0:
  3051. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3052. }
  3053. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3054. {
  3055. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3056. {
  3057. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3058. 0:
  3059. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3060. if(idxPeriod > 0)
  3061. {
  3062. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3063. {
  3064. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3065. }
  3066. }
  3067. }
  3068. }
  3069. }
  3070. }
  3071. /*
  3072. DEBUG_INFO("MaxProfile after align.\n");
  3073. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3074. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3075. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3076. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3077. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3078. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3079. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3080. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3081. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3082. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3083. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3084. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3085. {
  3086. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3087. {
  3088. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3089. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3090. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3091. }
  3092. }
  3093. DEBUG_INFO("------------------------------------\n");*/
  3094. }
  3095. /*
  3096. * Merge to conposite schedule
  3097. */
  3098. //DEBUG_INFO("====================================\n");
  3099. // Find each profile period quantity
  3100. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3101. {
  3102. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3103. limitMax = idx+1;
  3104. }
  3105. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3106. {
  3107. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3108. limitDef = idx+1;
  3109. }
  3110. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3111. {
  3112. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3113. limitTx = idx+1;
  3114. }
  3115. // TxProfile found, composite schedule based on it
  3116. if(txProfile.ChargingProfileId != -1)
  3117. {
  3118. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3119. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3120. {
  3121. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3122. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3123. (txProfile.ChargingSchedule.Duration > 0))
  3124. {
  3125. if(maxProfile.ChargingProfileId != -1)
  3126. {
  3127. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3128. {
  3129. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3130. {
  3131. if((maxProfile.ChargingSchedule.Duration > 0))
  3132. {
  3133. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3134. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3135. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3136. }
  3137. else
  3138. {
  3139. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3140. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3141. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3142. }
  3143. }
  3144. if(idxMaxPeriod == (limitMax-1))
  3145. {
  3146. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3147. {
  3148. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3149. {
  3150. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3151. compositePeriodIdx++;
  3152. }
  3153. else
  3154. {
  3155. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3156. }
  3157. }
  3158. }
  3159. }
  3160. }
  3161. else
  3162. {
  3163. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3164. {
  3165. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3166. compositePeriodIdx++;
  3167. }
  3168. else
  3169. {
  3170. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3171. }
  3172. }
  3173. }
  3174. if(idxTxPeriod == (limitTx-1))
  3175. {
  3176. if(defaultTxProfile.ChargingProfileId != -1)
  3177. {
  3178. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3179. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3180. {
  3181. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3182. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3183. (defaultTxProfile.ChargingSchedule.Duration>0))
  3184. {
  3185. if(maxProfile.ChargingProfileId != -1)
  3186. {
  3187. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3188. {
  3189. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3190. {
  3191. if((maxProfile.ChargingSchedule.Duration > 0))
  3192. {
  3193. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3194. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3195. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3196. }
  3197. else
  3198. {
  3199. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3200. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3201. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3202. }
  3203. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3204. {
  3205. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3206. {
  3207. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3208. compositePeriodIdx++;
  3209. }
  3210. else
  3211. {
  3212. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3213. }
  3214. }
  3215. // Delete duplicate period
  3216. if(compositePeriodIdx > 1)
  3217. {
  3218. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3219. {
  3220. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3221. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3222. compositePeriodIdx -= 1;
  3223. }
  3224. }
  3225. }
  3226. else
  3227. {
  3228. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3229. {
  3230. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3231. compositePeriodIdx++;
  3232. }
  3233. else
  3234. {
  3235. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3236. }
  3237. break;
  3238. }
  3239. }
  3240. }
  3241. else
  3242. {
  3243. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3244. {
  3245. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3246. compositePeriodIdx++;
  3247. }
  3248. else
  3249. {
  3250. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3251. }
  3252. }
  3253. }
  3254. }
  3255. }
  3256. }
  3257. }
  3258. }
  3259. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3260. else if(defaultTxProfile.ChargingProfileId != -1)
  3261. {
  3262. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3263. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3264. {
  3265. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3266. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3267. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3268. {
  3269. if(maxProfile.ChargingProfileId != -1)
  3270. {
  3271. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3272. {
  3273. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3274. {
  3275. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3276. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3277. if((maxProfile.ChargingSchedule.Duration > 0))
  3278. {
  3279. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3280. }
  3281. else
  3282. {
  3283. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3284. }
  3285. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3286. {
  3287. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3288. {
  3289. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3290. compositePeriodIdx++;
  3291. }
  3292. else
  3293. {
  3294. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3295. }
  3296. }
  3297. // Delete duplicate period
  3298. if(compositePeriodIdx > 1)
  3299. {
  3300. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3301. {
  3302. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3303. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3304. compositePeriodIdx -= 1;
  3305. }
  3306. }
  3307. }
  3308. else
  3309. {
  3310. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3311. {
  3312. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3313. compositePeriodIdx++;
  3314. }
  3315. else
  3316. {
  3317. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3318. }
  3319. break;
  3320. }
  3321. }
  3322. }
  3323. else
  3324. {
  3325. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3326. {
  3327. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3328. compositePeriodIdx++;
  3329. }
  3330. else
  3331. {
  3332. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3333. }
  3334. }
  3335. }
  3336. }
  3337. }
  3338. // Fill other period by MaxProfile
  3339. if(maxProfile.ChargingProfileId != -1)
  3340. {
  3341. if(compositePeriodIdx==0)
  3342. {
  3343. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3344. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3345. {
  3346. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3347. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3348. (maxProfile.ChargingSchedule.Duration > 0))
  3349. {
  3350. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3351. {
  3352. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3353. compositePeriodIdx++;
  3354. }
  3355. else
  3356. {
  3357. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3358. }
  3359. }
  3360. }
  3361. }
  3362. else
  3363. {
  3364. int lastCompositePeriodIdx = compositePeriodIdx;
  3365. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3366. {
  3367. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3368. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3369. (maxProfile.ChargingSchedule.Duration > 0))
  3370. {
  3371. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3372. {
  3373. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3374. {
  3375. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3376. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3377. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3378. }
  3379. else
  3380. {
  3381. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3382. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3383. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3384. }
  3385. }
  3386. if(tmpPeriod.Limit != -1)
  3387. {
  3388. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3389. {
  3390. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3391. {
  3392. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3393. compositePeriodIdx++;
  3394. }
  3395. else
  3396. {
  3397. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3398. }
  3399. }
  3400. // Delete duplicate period
  3401. if(compositePeriodIdx > 1)
  3402. {
  3403. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3404. {
  3405. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3406. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3407. compositePeriodIdx -= 1;
  3408. }
  3409. }
  3410. }
  3411. }
  3412. }
  3413. }
  3414. }
  3415. compositeProfile.ChargingSchedule.Duration = durationReq;
  3416. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3417. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3418. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3419. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3420. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3421. {
  3422. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3423. {
  3424. compositeProfile.ChargingProfileId = 1;
  3425. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3426. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3427. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3428. }
  3429. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3430. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3431. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3432. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3433. }
  3434. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3435. if(line)
  3436. free(line);
  3437. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3438. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3439. }
  3440. //==========================================
  3441. // Init all share memory
  3442. //==========================================
  3443. int InitShareMemory()
  3444. {
  3445. int result = PASS;
  3446. int MeterSMId;
  3447. //creat ShmSysConfigAndInfo
  3448. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3449. {
  3450. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3451. result = FAIL;
  3452. }
  3453. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3454. {
  3455. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3456. result = FAIL;
  3457. }
  3458. else
  3459. {}
  3460. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3461. {
  3462. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3463. result = FAIL;
  3464. }
  3465. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3466. {
  3467. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3468. result = FAIL;
  3469. }
  3470. else
  3471. {}
  3472. //creat ShmPsuData
  3473. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3474. {
  3475. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3476. result = FAIL;
  3477. }
  3478. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3479. {
  3480. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3481. result = FAIL;
  3482. }
  3483. else
  3484. {}
  3485. //link ShmOCPP16Data
  3486. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3487. {
  3488. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3489. result = FAIL;
  3490. }
  3491. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3492. {
  3493. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3494. result = FAIL;
  3495. }
  3496. else
  3497. {}
  3498. //creat ShmOCPP16DataPH
  3499. if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3500. {
  3501. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3502. result = FAIL;
  3503. }
  3504. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3505. {
  3506. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3507. result = FAIL;
  3508. }
  3509. else
  3510. {}
  3511. /****************************** For Initial Settings************************************************/
  3512. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3513. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3514. // allocate Configuration memory address
  3515. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3516. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3517. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3518. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3519. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3520. //offline MeterValue Interval
  3521. TempMeterValueInterval = 0;
  3522. return result;
  3523. }
  3524. int ProcessShareMemory()
  3525. {
  3526. int result = PASS;
  3527. if(InitShareMemory() == FAIL)
  3528. {
  3529. DEBUG_ERROR("InitShareMemory NG\n");
  3530. if(ShmStatusCodeData!=NULL)
  3531. {
  3532. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3533. }
  3534. result = FAIL;
  3535. }
  3536. // Model name parsing
  3537. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3538. {
  3539. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3540. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3541. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3542. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3543. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3544. ) // 'D' means DC
  3545. {
  3546. // DO series
  3547. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3548. {
  3549. gunTotalNumber += 1;
  3550. gunType[gun_index] = GUN_TYPE_DO;
  3551. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3552. {
  3553. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3554. {
  3555. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3556. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3557. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3558. }
  3559. }
  3560. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3561. {
  3562. case Gun_Type_Chademo:
  3563. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3564. break;
  3565. case Gun_Type_CCS_2:
  3566. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3567. break;
  3568. case Gun_Type_GB:
  3569. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3570. break;
  3571. case Gun_Type_AC:
  3572. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3573. break;
  3574. default:
  3575. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3576. break;
  3577. }
  3578. }
  3579. }
  3580. else
  3581. {
  3582. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3583. {
  3584. gunTotalNumber += 1;
  3585. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3586. {
  3587. case Gun_Type_Chademo:
  3588. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3589. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3590. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  3591. {
  3592. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  3593. {
  3594. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3595. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3596. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  3597. }
  3598. }
  3599. break;
  3600. case Gun_Type_CCS_2:
  3601. gunType[gun_index] = GUN_TYPE_CCS;
  3602. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3603. for (int index = 0; index < CCS_QUANTITY; index++)
  3604. {
  3605. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  3606. {
  3607. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3608. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3609. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  3610. }
  3611. }
  3612. break;
  3613. case Gun_Type_GB:
  3614. gunType[gun_index] = GUN_TYPE_GBT;
  3615. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3616. for (int index = 0; index < GB_QUANTITY; index++)
  3617. {
  3618. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  3619. {
  3620. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3621. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3622. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  3623. }
  3624. }
  3625. break;
  3626. case Gun_Type_AC:
  3627. gunType[gun_index] = GUN_TYPE_AC;
  3628. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3629. for (int index = 0; index < AC_QUANTITY; index++)
  3630. {
  3631. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  3632. {
  3633. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3634. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3635. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  3636. }
  3637. }
  3638. break;
  3639. default:
  3640. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3641. break;
  3642. }
  3643. }
  3644. }
  3645. }
  3646. else
  3647. {
  3648. DEBUG_ERROR("Model name parsing fail.\n");
  3649. result = FAIL;
  3650. }
  3651. if(result != PASS)sleep(5);
  3652. return result;
  3653. }
  3654. void checkRemoteStart(uint8_t connectorIdInt)
  3655. {
  3656. uint8_t tempIndex;
  3657. int result = PASS;
  3658. char cmdBuf[512];
  3659. //check Transaction active
  3660. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3661. {
  3662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3663. {
  3664. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3665. }
  3666. else
  3667. {
  3668. tempIndex = connectorIdInt -1;
  3669. }
  3670. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3671. {
  3672. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3673. {
  3674. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3675. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3676. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3677. {
  3678. //Reserved
  3679. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3680. }
  3681. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3682. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3683. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3684. {
  3685. //Reserved
  3686. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3687. result = FAIL;
  3688. goto end;
  3689. }
  3690. else
  3691. {
  3692. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3693. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3694. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3695. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3696. {
  3697. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3698. result = FAIL;
  3699. goto end;
  3700. }
  3701. }//END FOR ELSE
  3702. }
  3703. }// END FOR CHAdeMO_QUANTITY
  3704. }
  3705. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3706. {
  3707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3708. {
  3709. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3710. }
  3711. else
  3712. {
  3713. tempIndex = connectorIdInt -1;
  3714. }
  3715. for (int index = 0; index < CCS_QUANTITY; index++)
  3716. {
  3717. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3718. {
  3719. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3720. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3721. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3722. {
  3723. //Reserved
  3724. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3725. }
  3726. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3727. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3728. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3729. {
  3730. //Reserved
  3731. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3732. result = FAIL;
  3733. goto end;
  3734. }
  3735. else
  3736. {
  3737. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3738. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3739. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3740. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3741. {
  3742. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3743. result = FAIL;
  3744. goto end;
  3745. }
  3746. }// END FOR ELSE
  3747. }
  3748. }// END FOR CCS_QUANTITY
  3749. }
  3750. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3751. {
  3752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3753. {
  3754. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3755. }
  3756. else
  3757. {
  3758. tempIndex = connectorIdInt -1;
  3759. }
  3760. for (int index = 0; index < GB_QUANTITY; index++)
  3761. {
  3762. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3763. {
  3764. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3765. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3766. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3767. {
  3768. //Reserved
  3769. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3770. }
  3771. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3772. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3773. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3774. {
  3775. //Reserved
  3776. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3777. result = FAIL;
  3778. goto end;
  3779. }
  3780. else
  3781. {
  3782. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3783. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3784. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3785. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3786. {
  3787. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3788. result = FAIL;
  3789. goto end;
  3790. }
  3791. }// END FOR ELSE
  3792. }
  3793. } // END FOR GB_QUANTITY
  3794. }
  3795. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3796. {
  3797. tempIndex = connectorIdInt -1;
  3798. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3799. {
  3800. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3801. {
  3802. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3803. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3804. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3805. {
  3806. //Reserved
  3807. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3808. }
  3809. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3810. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3811. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3812. {
  3813. //Reserved
  3814. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3815. result = FAIL;
  3816. goto end;
  3817. }
  3818. else
  3819. {
  3820. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3821. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3822. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3823. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3824. {
  3825. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3826. result = FAIL;
  3827. goto end;
  3828. }
  3829. }// END FOR ELSE
  3830. }
  3831. } // END FOR GB_QUANTITY
  3832. }
  3833. else
  3834. {
  3835. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3836. {
  3837. tempIndex = 2;
  3838. }
  3839. else
  3840. {
  3841. tempIndex = connectorIdInt -1;
  3842. }
  3843. for (int index = 0; index < AC_QUANTITY; index++)
  3844. {
  3845. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3846. {
  3847. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3848. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3849. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3850. {
  3851. //Reserved
  3852. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3853. }
  3854. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3855. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3856. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3857. {
  3858. //Reserved
  3859. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3860. result = FAIL;
  3861. goto end;
  3862. }
  3863. else
  3864. {
  3865. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3866. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3867. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3868. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3869. {
  3870. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3871. result = FAIL;
  3872. goto end;
  3873. }
  3874. }//END FOR ELSE
  3875. }
  3876. }// END FOR AC_QUANTITY
  3877. }
  3878. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3879. {
  3880. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3881. {
  3882. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3883. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3884. {
  3885. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3886. system(cmdBuf);
  3887. }
  3888. }
  3889. else
  3890. {
  3891. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3892. result = FAIL;
  3893. }
  3894. }
  3895. end:
  3896. if(result == PASS)
  3897. {
  3898. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3899. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3900. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3901. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3902. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3903. }
  3904. }
  3905. void CheckSystemValue(void)
  3906. {
  3907. char filenmae[100]={0};
  3908. char str[100]={0};
  3909. int tempIndex = 0;
  3910. //===============================
  3911. // send Heartbeat
  3912. //===============================
  3913. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3914. {
  3915. //parameter for test
  3916. sendHeartbeatRequest(0);
  3917. //==============================================
  3918. // Reset Waiting Time
  3919. //==============================================
  3920. HeartBeatWithNOResponse += 2;
  3921. }
  3922. //===============================
  3923. // Credit deduct report
  3924. //===============================
  3925. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3926. {
  3927. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3928. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3929. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3930. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3931. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3932. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3933. }
  3934. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3935. {
  3936. OCPP_query_deduct_info();
  3937. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3938. }
  3939. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3940. {
  3941. // ClockAlign MeterValue
  3942. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3943. {
  3944. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3945. {
  3946. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3947. {
  3948. tempIndex = ((gun_index==2) ? 1: 0);
  3949. }
  3950. else
  3951. {
  3952. tempIndex = gun_index;
  3953. }
  3954. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3955. {
  3956. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3957. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3958. {
  3959. reqClockAlignMeter[gun_index] = 1;
  3960. }
  3961. }// End for CHAdeMO
  3962. }
  3963. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3964. {
  3965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3966. {
  3967. tempIndex = ((gun_index==2) ? 1: 0);
  3968. }
  3969. else
  3970. {
  3971. tempIndex = gun_index;
  3972. }
  3973. for (int index = 0; index < CCS_QUANTITY; index++)
  3974. {
  3975. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3976. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3977. {
  3978. reqClockAlignMeter[gun_index] = 1;
  3979. }
  3980. } // End for CCS
  3981. }
  3982. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3983. {
  3984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3985. {
  3986. tempIndex = ((gun_index==2) ? 1: 0);
  3987. }
  3988. else
  3989. {
  3990. tempIndex = gun_index;
  3991. }
  3992. for (int index = 0; index < GB_QUANTITY; index++)
  3993. {
  3994. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3995. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3996. {
  3997. reqClockAlignMeter[gun_index] = 1;
  3998. }
  3999. }// End for GB
  4000. }
  4001. else if(gunType[gun_index] == GUN_TYPE_DO)
  4002. {
  4003. tempIndex = gun_index;
  4004. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4005. {
  4006. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4007. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4008. {
  4009. reqClockAlignMeter[gun_index] = 1;
  4010. }
  4011. }
  4012. }
  4013. else
  4014. {
  4015. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4016. {
  4017. tempIndex = 2;
  4018. }
  4019. else
  4020. {
  4021. tempIndex = gun_index;
  4022. }
  4023. for (int index = 0; index < AC_QUANTITY; index++)
  4024. {
  4025. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4026. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4027. {
  4028. reqClockAlignMeter[gun_index] = 1;
  4029. }
  4030. }//End for AC
  4031. }
  4032. }
  4033. }
  4034. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4035. {
  4036. //==========================================
  4037. // Check remote start without connector id
  4038. //==========================================
  4039. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  4040. {
  4041. int connectorIdInt = -1;
  4042. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4043. {
  4044. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4045. {
  4046. connectorIdInt = (gun_index+1);
  4047. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4048. checkRemoteStart(connectorIdInt);
  4049. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4050. break;
  4051. }
  4052. }
  4053. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4054. {
  4055. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4056. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4057. }
  4058. }
  4059. //==========================================
  4060. // csu trigger DataTransferReq
  4061. //==========================================
  4062. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4063. {
  4064. sendDataTransferRequest(gun_index);
  4065. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4066. }
  4067. //===============================
  4068. // CSU Trigger Authorize Request
  4069. //===============================
  4070. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4071. {
  4072. sendAuthorizeRequest(0);
  4073. authorizeRetryTimes = authorizeRetryTimes + 1;
  4074. if(authorizeRetryTimes < 3)
  4075. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4076. }
  4077. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4078. {
  4079. authorizeRetryTimes = 0;
  4080. SetOcppConnStatus(FALSE);
  4081. server_sign = FALSE;
  4082. }
  4083. 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))
  4084. {
  4085. sendAuthorizeRequest(0);
  4086. }
  4087. //==============================================
  4088. // Charger start transaction
  4089. //==============================================
  4090. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4091. {
  4092. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4093. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4094. sendStartTransactionRequest(gun_index);
  4095. refreshStartTimer(&clientTime.StartTransaction);
  4096. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4097. //storeTempStopTransaction(gun_index);
  4098. }
  4099. //==============================================
  4100. // Charger stop transaction
  4101. //==============================================
  4102. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4103. {
  4104. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4105. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4106. sendStopTransactionRequest(gun_index);
  4107. refreshStartTimer(&clientTime.StopTransaction);
  4108. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4109. }
  4110. //==============================================
  4111. // Charger status report
  4112. //==============================================
  4113. //--- Check Mode Change ---//
  4114. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4115. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4116. {
  4117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4118. {
  4119. tempIndex = ((gun_index==2) ? 1: 0);
  4120. }
  4121. else
  4122. {
  4123. tempIndex = gun_index;
  4124. }
  4125. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4126. {
  4127. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4128. {
  4129. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4130. {
  4131. // Sent unplug message for California pricing logic
  4132. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4133. {
  4134. uint8_t ts[36];
  4135. getNowDatetime(ts);
  4136. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4137. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4138. if(strcmp((char*)dmsVersion, "2.0")==0)
  4139. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4140. else
  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.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4146. {
  4147. interLock.isSentUnplug[gun_index] = 0;
  4148. }
  4149. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4150. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4151. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4152. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[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.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4164. #if 1 // for TempStopTransaction
  4165. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[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_CCS)
  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 < CCS_QUANTITY; index++)
  4185. {
  4186. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4187. {
  4188. 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]*/ )
  4189. {
  4190. // Sent unplug message for California pricing logic
  4191. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[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. if(strcmp((char*)dmsVersion, "2.0")==0)
  4198. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4199. else
  4200. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4201. sendUnplugByDataTransferRequest(gun_index);
  4202. interLock.isSentUnplug[gun_index] = 1;
  4203. }
  4204. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4205. {
  4206. interLock.isSentUnplug[gun_index] = 0;
  4207. }
  4208. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4209. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4210. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4211. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4212. {
  4213. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4214. if((access(filenmae,F_OK))!=-1)
  4215. {
  4216. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4217. sprintf(str,"rm -f %s",filenmae);
  4218. system(str);
  4219. }
  4220. }
  4221. }
  4222. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4223. #if 1 // for TempStopTransaction
  4224. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4225. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4226. {
  4227. checkTempStopTransaction(gun_index);
  4228. }
  4229. #endif
  4230. }
  4231. }
  4232. }
  4233. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4234. {
  4235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4236. {
  4237. tempIndex = ((gun_index==2) ? 1: 0);
  4238. }
  4239. else
  4240. {
  4241. tempIndex = gun_index;
  4242. }
  4243. for (int index = 0; index < GB_QUANTITY; index++)
  4244. {
  4245. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4246. {
  4247. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4248. {
  4249. // Sent unplug message for California pricing logic
  4250. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4251. {
  4252. uint8_t ts[36];
  4253. getNowDatetime(ts);
  4254. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4255. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4256. if(strcmp((char*)dmsVersion, "2.0")==0)
  4257. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4258. else
  4259. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4260. sendUnplugByDataTransferRequest(gun_index);
  4261. interLock.isSentUnplug[gun_index] = 1;
  4262. }
  4263. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4264. {
  4265. interLock.isSentUnplug[gun_index] = 0;
  4266. }
  4267. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4268. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4269. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4270. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4271. {
  4272. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4273. if((access(filenmae,F_OK))!=-1)
  4274. {
  4275. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4276. sprintf(str,"rm -f %s",filenmae);
  4277. system(str);
  4278. }
  4279. }
  4280. }
  4281. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4282. #if 1 // for TempStopTransaction
  4283. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4284. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4285. {
  4286. checkTempStopTransaction(gun_index);
  4287. }
  4288. #endif
  4289. }
  4290. }
  4291. }
  4292. else if(gunType[gun_index] == GUN_TYPE_DO)
  4293. {
  4294. tempIndex = gun_index;
  4295. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4296. {
  4297. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4298. {
  4299. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4300. {
  4301. // Sent unplug message for California pricing logic
  4302. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4303. {
  4304. uint8_t ts[36];
  4305. getNowDatetime(ts);
  4306. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4307. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4308. if(strcmp((char*)dmsVersion, "2.0")==0)
  4309. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4310. else
  4311. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4312. sendUnplugByDataTransferRequest(gun_index);
  4313. interLock.isSentUnplug[gun_index] = 1;
  4314. }
  4315. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4316. {
  4317. interLock.isSentUnplug[gun_index] = 0;
  4318. }
  4319. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4320. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4321. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4322. 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
  4323. {
  4324. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4325. if((access(filenmae,F_OK))!=-1)
  4326. {
  4327. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4328. sprintf(str,"rm -f %s",filenmae);
  4329. system(str);
  4330. }
  4331. }
  4332. }
  4333. 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);
  4334. #if 1 // for TempStopTransaction
  4335. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4336. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4337. {
  4338. checkTempStopTransaction(gun_index);
  4339. }
  4340. #endif
  4341. }
  4342. }
  4343. }
  4344. else
  4345. {
  4346. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4347. {
  4348. tempIndex = 2;
  4349. }
  4350. else
  4351. {
  4352. tempIndex = gun_index;
  4353. }
  4354. for (int index = 0; index < AC_QUANTITY; index++)
  4355. {
  4356. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4357. {
  4358. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4359. {
  4360. // Sent unplug message for California pricing logic
  4361. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4362. {
  4363. uint8_t ts[36];
  4364. getNowDatetime(ts);
  4365. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4366. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4367. if(strcmp((char*)dmsVersion, "2.0")==0)
  4368. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4369. else
  4370. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4371. sendUnplugByDataTransferRequest(gun_index);
  4372. interLock.isSentUnplug[gun_index] = 1;
  4373. }
  4374. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4375. {
  4376. interLock.isSentUnplug[gun_index] = 0;
  4377. }
  4378. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4379. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4380. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4381. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4382. {
  4383. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4384. if((access(filenmae,F_OK))!=-1)
  4385. {
  4386. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4387. sprintf(str,"rm -f %s",filenmae);
  4388. system(str);
  4389. }
  4390. }
  4391. }
  4392. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4393. #if 1 // for TempStopTransaction
  4394. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4395. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4396. {
  4397. checkTempStopTransaction(gun_index);
  4398. }
  4399. #endif
  4400. }
  4401. }// END
  4402. }
  4403. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4404. (
  4405. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4406. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4407. )
  4408. )
  4409. {
  4410. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4411. sendStatusNotificationRequest(gun_index);
  4412. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4413. }
  4414. //==============================================
  4415. // TCCI reader status report
  4416. //==============================================
  4417. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4418. {
  4419. reportReaderStatus(gun_index);
  4420. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4421. }
  4422. //==============================================
  4423. // CSU Trigger or timer timeout refresh Smart Charging Profile
  4424. //==============================================
  4425. if((ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  4426. ((cpinitateMsg.bits[gun_index].isOnCharging) && (atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData) > 0) && (getDiffSecNow(clientTime.CharingProfileRefresh[gun_index]) > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData))))
  4427. {
  4428. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4429. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4430. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  4431. }
  4432. //==============================================
  4433. // Meter report
  4434. //==============================================
  4435. // Trigger MeterValue
  4436. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4437. {
  4438. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4439. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4440. }
  4441. // Clock-aligned Meter value
  4442. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4443. {
  4444. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4445. reqClockAlignMeter[gun_index] = 0;
  4446. }
  4447. // Sample period MeterValue
  4448. 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))))
  4449. {
  4450. //check Transaction active
  4451. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4452. {
  4453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4454. {
  4455. tempIndex = ((gun_index==2) ? 1: 0);
  4456. }
  4457. else
  4458. {
  4459. tempIndex = gun_index;
  4460. }
  4461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4462. {
  4463. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4464. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4465. {
  4466. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4467. {
  4468. reqSampleMeter[gun_index] = 1;
  4469. }
  4470. }
  4471. }// End for CHAdeMO
  4472. }
  4473. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4474. {
  4475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4476. {
  4477. tempIndex = ((gun_index==2) ? 1: 0);
  4478. }
  4479. else
  4480. {
  4481. tempIndex = gun_index;
  4482. }
  4483. for (int index = 0; index < CCS_QUANTITY; index++)
  4484. {
  4485. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4486. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4487. {
  4488. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4489. {
  4490. reqSampleMeter[gun_index] = 1;
  4491. }
  4492. }
  4493. } // End for CCS
  4494. }
  4495. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4496. {
  4497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4498. {
  4499. tempIndex = ((gun_index==2) ? 1: 0);
  4500. }
  4501. else
  4502. {
  4503. tempIndex = gun_index;
  4504. }
  4505. for (int index = 0; index < GB_QUANTITY; index++)
  4506. {
  4507. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4508. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4509. {
  4510. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4511. {
  4512. reqSampleMeter[gun_index] = 1;
  4513. }
  4514. }
  4515. }// End for GB
  4516. }
  4517. else if(gunType[gun_index] == GUN_TYPE_DO)
  4518. {
  4519. tempIndex = gun_index;
  4520. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4521. {
  4522. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4523. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4524. {
  4525. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4526. {
  4527. reqSampleMeter[gun_index] = 1;
  4528. }
  4529. }
  4530. }
  4531. }
  4532. else
  4533. {
  4534. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4535. {
  4536. tempIndex = 2;
  4537. }
  4538. else
  4539. {
  4540. tempIndex = gun_index;
  4541. }
  4542. for (int index = 0; index < AC_QUANTITY; index++)
  4543. {
  4544. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4545. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4546. {
  4547. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4548. {
  4549. reqSampleMeter[gun_index] = 1;
  4550. }
  4551. }
  4552. }//End for AC
  4553. }
  4554. if(reqSampleMeter[gun_index] == 1)
  4555. {
  4556. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4557. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4558. //storeTempStopTransaction(gun_index);
  4559. reqSampleMeter[gun_index] = 0;
  4560. }
  4561. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4562. }
  4563. //==============================================
  4564. // Check Connector reserved
  4565. //==============================================
  4566. //===============================
  4567. // Check if Reserve is expired
  4568. //===============================
  4569. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4570. {
  4571. double diff_t;
  4572. struct tm tp;
  4573. // current time
  4574. time_t t = time(NULL);
  4575. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4576. tp.tm_isdst = -1;
  4577. time_t utc = mktime(&tp);
  4578. diff_t = difftime(utc, t);
  4579. if(diff_t <= 0)
  4580. {
  4581. DEBUG_INFO("reserve expired.\n");
  4582. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4583. }
  4584. }//END OF Check if Reserve is expired
  4585. //==========================================
  4586. // csu trigger FirmwareStatusNotificationReq
  4587. //==========================================
  4588. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4589. {
  4590. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4591. }
  4592. //==========================================
  4593. // csu trigger DiagnosticsStatusNotificationReq
  4594. //==========================================
  4595. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4596. {
  4597. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4598. }
  4599. //==========================================
  4600. // csu trigger CancelReservationConf
  4601. //==========================================
  4602. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4603. {
  4604. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4605. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4606. }
  4607. //==========================================
  4608. // csu trigger ChangeAvailabilityConf
  4609. //==========================================
  4610. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4611. {
  4612. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4613. }
  4614. //==========================================
  4615. // csu trigger UnlockConnectorConf
  4616. //==========================================
  4617. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4618. {
  4619. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4620. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4621. }
  4622. //==========================================
  4623. // csu trigger ReserveNowConf
  4624. //==========================================
  4625. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4626. {
  4627. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4628. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4629. }
  4630. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4631. {
  4632. sendSignCertificateRequest();
  4633. }
  4634. }
  4635. }
  4636. //==========================================
  4637. // send request routine
  4638. //==========================================
  4639. int sendAuthorizeRequest(int gun_index)
  4640. {
  4641. mtrace();
  4642. int result = FAIL;
  4643. char message[100]={0};
  4644. char guid[37];
  4645. char tempdata[65]={0};
  4646. DEBUG_INFO("sendAuthorizeRequest...\n");
  4647. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4648. //Local Authorize
  4649. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4650. {
  4651. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4652. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4653. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4654. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4655. result = PASS;
  4656. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4657. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4658. authorizeRetryTimes = 0;
  4659. return result;
  4660. }
  4661. 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))||
  4662. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4663. {
  4664. // Query from cache
  4665. DEBUG_INFO("Authorize from cache.\n");
  4666. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4667. // Query from list
  4668. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4669. {
  4670. DEBUG_INFO("Authorize from list.\n");
  4671. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4672. }
  4673. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4674. {
  4675. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4676. {
  4677. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4678. }
  4679. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4680. {
  4681. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4682. }
  4683. if(!GetOcppConnStatus())
  4684. {
  4685. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4686. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4687. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4688. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4689. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4690. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4691. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4692. authorizeRetryTimes = 0;
  4693. return result;
  4694. }
  4695. }
  4696. else
  4697. {
  4698. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4699. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4700. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4701. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4702. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4703. else
  4704. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4705. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4706. result = PASS;
  4707. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4708. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4709. authorizeRetryTimes = 0;
  4710. return result;
  4711. }
  4712. }
  4713. //initialize struct Authorize
  4714. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4715. //get data from shared memory
  4716. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4717. random_uuid(guid);
  4718. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4719. LWS_Send(message);
  4720. sprintf(tempdata, "Authorize,%d", gun_index);
  4721. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4722. {
  4723. result = PASS;
  4724. DEBUG_INFO("Authorize mapItem pass\n");
  4725. }
  4726. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4727. return result;
  4728. }
  4729. int sendBootNotificationRequest(void)
  4730. {
  4731. mtrace();
  4732. int result = FAIL;
  4733. char message[500]={0}, payload[700]={0};
  4734. char guid[37]={0};
  4735. char tempdata[65]={0};
  4736. // Fill BootNotification fields
  4737. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4738. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4739. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4740. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4741. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4742. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4743. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4744. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4745. ShmOCPP16DataPH->ChargeBoxId
  4746. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4747. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4748. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4749. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4750. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4751. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4752. random_uuid(guid);
  4753. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4754. LWS_Send(message);
  4755. sprintf(tempdata, "BootNotification,0");
  4756. 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*/)
  4757. {
  4758. result = PASS;
  4759. }
  4760. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4761. strcpy(queuedata,message);
  4762. return result;
  4763. }
  4764. int sendDataTransferRequest(int gun_index)
  4765. {
  4766. mtrace();
  4767. char message[1000]={0};
  4768. char guid[37]={0};
  4769. char tempdata[65]={0};
  4770. int result = FAIL;
  4771. random_uuid(guid);
  4772. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4773. MESSAGE_TYPE_CALL,
  4774. guid,
  4775. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4776. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4777. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4778. LWS_Send(message);
  4779. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4780. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4781. {
  4782. result = PASS;
  4783. DEBUG_INFO("DataTransfer mapItem pass\n");
  4784. }
  4785. return result;
  4786. }
  4787. int sendUnplugByDataTransferRequest(int gun_index)
  4788. {
  4789. mtrace();
  4790. char message[1000]={0};
  4791. char guid[37]={0};
  4792. char tempdata[65]={0};
  4793. int result = FAIL;
  4794. random_uuid(guid);
  4795. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4796. (gun_index+1),
  4797. MESSAGE_TYPE_CALL,
  4798. guid,
  4799. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4800. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4801. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4802. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4803. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4804. {
  4805. result = PASS;
  4806. DEBUG_INFO("DataTransfer mapItem pass\n");
  4807. }
  4808. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  4809. return result;
  4810. }
  4811. int sendDiagnosticsStatusNotificationRequest(char *status)
  4812. {
  4813. mtrace();
  4814. int result = FAIL;
  4815. char message[110]={0};
  4816. char guid[37]={0};
  4817. char tempdata[65]={0};
  4818. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4819. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4820. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4821. random_uuid(guid);
  4822. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4823. LWS_SendNow(message);
  4824. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4825. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4826. {
  4827. result = PASS;
  4828. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4829. }
  4830. //#ifdef SystemLogMessage
  4831. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4832. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4833. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4834. //#endif
  4835. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4836. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4837. //record status
  4838. if(strcmp(status,"Idle")==0)
  4839. {
  4840. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4841. }
  4842. else if(strcmp(status,"Uploaded")==0)
  4843. {
  4844. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4845. }
  4846. else if(strcmp(status,"UploadFailed")==0)
  4847. {
  4848. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4849. }
  4850. else if(strcmp(status,"Uploading")==0)
  4851. {
  4852. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4853. }
  4854. return result;
  4855. }
  4856. int sendFirmwareStatusNotificationRequest(char *status)
  4857. {
  4858. mtrace();
  4859. int result = FAIL;
  4860. char message[110]={0};
  4861. char guid[37]={0};
  4862. char tempdata[65]={0};
  4863. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4864. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4865. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4866. random_uuid(guid);
  4867. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4868. LWS_SendNow(message);
  4869. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4870. 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*/)
  4871. {
  4872. result = PASS;
  4873. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4874. }
  4875. //#ifdef SystemLogMessage
  4876. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4877. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4878. //#endif
  4879. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4880. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4881. //record status
  4882. if(strcmp(status,"Downloaded")==0)
  4883. {
  4884. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4885. }
  4886. else if(strcmp(status,"DownloadFailed")==0)
  4887. {
  4888. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4889. }
  4890. else if(strcmp(status,"Downloading")==0)
  4891. {
  4892. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4893. }
  4894. else if(strcmp(status,"Idle")==0)
  4895. {
  4896. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4897. }
  4898. else if(strcmp(status,"InstallationFailed")==0)
  4899. {
  4900. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4901. }
  4902. else if(strcmp(status,"Installing")==0)
  4903. {
  4904. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4905. }
  4906. else if(strcmp(status,"Installed")==0)
  4907. {
  4908. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4909. }
  4910. return result;
  4911. }
  4912. int sendHeartbeatRequest(int gun_index)
  4913. {
  4914. mtrace();
  4915. int result = FAIL;
  4916. char message[80]={0};
  4917. char guid[37]={0};
  4918. char tempdata[65]={0};
  4919. random_uuid(guid);
  4920. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4921. , MESSAGE_TYPE_CALL
  4922. , guid );
  4923. LWS_Send(message);
  4924. sprintf(tempdata, "Heartbeat,%d", 0);
  4925. 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*/)
  4926. {
  4927. result = PASS;
  4928. }
  4929. return result;
  4930. }
  4931. int sendStartTransactionRequest(int gun_index)
  4932. {
  4933. mtrace();
  4934. int result = FAIL;
  4935. char message[250]={0};
  4936. char guid[37]={0};
  4937. struct timeval tmnow;
  4938. struct tm *tm;
  4939. char buf[28];//, usec_buf[6];
  4940. char tempdata[65]={0};
  4941. int tempIndex = 0;
  4942. DEBUG_INFO("sendStartTransactionRequest...\n");
  4943. gettimeofday(&tmnow, NULL);
  4944. time_t t;
  4945. t = time(NULL);
  4946. /*UTC time and date*/
  4947. tm = gmtime(&t);
  4948. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4949. #if 0 // remove temporally
  4950. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4951. strcat(buf,".");
  4952. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4953. strcat(buf,usec_buf);
  4954. #endif
  4955. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4956. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4957. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4958. // clear StartTransaction Response
  4959. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4960. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4961. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4962. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4963. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4964. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4965. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4966. {
  4967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4968. {
  4969. tempIndex = ((gun_index==2) ? 1: 0);
  4970. }
  4971. else
  4972. {
  4973. tempIndex = gun_index;
  4974. }
  4975. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4976. {
  4977. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4978. {
  4979. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4980. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4981. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4982. }
  4983. }
  4984. }
  4985. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4986. {
  4987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4988. {
  4989. tempIndex = ((gun_index==2) ? 1: 0);
  4990. }
  4991. else
  4992. {
  4993. tempIndex = gun_index;
  4994. }
  4995. for (int index = 0; index < CCS_QUANTITY; index++)
  4996. {
  4997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4998. {
  4999. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5000. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5001. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5002. }
  5003. }
  5004. }
  5005. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5006. {
  5007. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5008. {
  5009. tempIndex = ((gun_index==2) ? 1: 0);
  5010. }
  5011. else
  5012. {
  5013. tempIndex = gun_index;
  5014. }
  5015. for (int index = 0; index < GB_QUANTITY; index++)
  5016. {
  5017. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5018. {
  5019. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5020. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5021. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5022. }
  5023. }
  5024. }
  5025. else if(gunType[gun_index] == GUN_TYPE_DO)
  5026. {
  5027. tempIndex = gun_index;
  5028. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5029. {
  5030. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5031. {
  5032. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5033. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5034. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5035. }
  5036. }
  5037. }
  5038. else
  5039. {
  5040. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5041. {
  5042. tempIndex = 2;
  5043. }
  5044. else
  5045. {
  5046. tempIndex = gun_index;
  5047. }
  5048. for (int index = 0; index < AC_QUANTITY; index++)
  5049. {
  5050. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5051. {
  5052. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5053. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5054. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5055. }
  5056. }
  5057. }
  5058. random_uuid(guid);
  5059. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5060. {
  5061. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5062. , gun_index +1
  5063. , MESSAGE_TYPE_CALL
  5064. , guid
  5065. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5066. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5067. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5068. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5069. }
  5070. else
  5071. {
  5072. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5073. , gun_index +1
  5074. , MESSAGE_TYPE_CALL
  5075. , guid
  5076. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5077. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5078. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5079. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  5080. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5081. }
  5082. #if 1
  5083. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5084. 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*/)
  5085. {
  5086. result = PASS;
  5087. }
  5088. #endif
  5089. strcpy(queuedata, message);
  5090. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5091. OCPP_insert_transaction_msg(YES, queuedata);
  5092. return result;
  5093. }
  5094. int sendStatusNotificationRequest(int gun_index)
  5095. {
  5096. mtrace();
  5097. int result = FAIL;
  5098. char message[600]={0};
  5099. char guid[37];
  5100. int currentStatus = 0;
  5101. struct timeval tmnow;
  5102. struct tm *tm;
  5103. char buf[28];//, usec_buf[6];
  5104. char tempdata[65]={0};
  5105. int tempIndex = 0;
  5106. uint8_t isStateChanged = TRUE;
  5107. uint8_t isContentIllegal = TRUE;
  5108. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5109. gettimeofday(&tmnow, NULL);
  5110. time_t t;
  5111. t = time(NULL);
  5112. /*UTC time and date*/
  5113. tm = gmtime(&t);
  5114. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5115. #if 0 // remove temporally
  5116. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5117. strcat(buf,".");
  5118. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5119. strcat(buf,usec_buf);
  5120. #endif
  5121. //printf("%s",buf);
  5122. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5123. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5124. // it's option
  5125. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5126. /*
  5127. enum _SYSTEM_STATUS
  5128. {
  5129. S_BOOTING = 0,
  5130. S_IDLE, = 1
  5131. S_AUTHORIZING, =2
  5132. S_REASSIGN_CHECK, =3
  5133. S_REASSIGN, =4
  5134. S_PRECHARGE, =5
  5135. S_PREPARING_FOR_EV, =6
  5136. S_PREPARING_FOR_EVSE, =7
  5137. S_CHARGING, =8
  5138. S_TERMINATING, =9
  5139. S_COMPLETE, =10
  5140. S_ALARM, =11
  5141. S_FAULT =12
  5142. }
  5143. */
  5144. //check Transaction active
  5145. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5146. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5147. {
  5148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5149. {
  5150. tempIndex = ((gun_index==2) ? 1: 0);
  5151. }
  5152. else
  5153. {
  5154. tempIndex = gun_index;
  5155. }
  5156. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5157. {
  5158. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5159. {
  5160. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5161. {
  5162. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5163. {
  5164. currentStatus = Preparing; //OCPP Status: Preparing
  5165. }
  5166. else
  5167. {
  5168. currentStatus = Available; //OCPP Status: Available
  5169. }
  5170. }
  5171. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5172. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5173. ) //S_PRECHARGE
  5174. {
  5175. currentStatus = Preparing; //OCPP Status: Preparing
  5176. }
  5177. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5178. {
  5179. currentStatus = Charging; //OCPP Status: Charging
  5180. }
  5181. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5182. {
  5183. currentStatus = Finishing; //OCPP Status: Finishing
  5184. }
  5185. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5186. {
  5187. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5188. }
  5189. 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
  5190. {
  5191. currentStatus = Unavailable; //OCPP Status: Unavailable
  5192. }
  5193. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5194. {
  5195. currentStatus = Faulted; //OCPP Status: Faulted
  5196. }
  5197. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5198. {
  5199. currentStatus = Reserved; //OCPP Status: Reserved
  5200. }
  5201. } //end of the same index
  5202. }//end of for CHAdeMO_QUANTITY
  5203. }
  5204. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5205. {
  5206. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5207. {
  5208. tempIndex = ((gun_index==2) ? 1: 0);
  5209. }
  5210. else
  5211. {
  5212. tempIndex = gun_index;
  5213. }
  5214. for (int index = 0; index < CCS_QUANTITY; index++)
  5215. {
  5216. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5217. {
  5218. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5219. {
  5220. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5221. {
  5222. currentStatus = Preparing; //OCPP Status: Preparing
  5223. }
  5224. else
  5225. {
  5226. currentStatus = Available; //OCPP Status: Available
  5227. }
  5228. }
  5229. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5230. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5231. ) //S_PRECHARGE
  5232. {
  5233. currentStatus = Preparing; //OCPP Status: Preparing
  5234. }
  5235. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5236. {
  5237. currentStatus = Charging; //OCPP Status: Charging
  5238. }
  5239. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5240. {
  5241. currentStatus = Finishing; //OCPP Status: Finishing
  5242. }
  5243. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5244. {
  5245. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5246. }
  5247. 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
  5248. {
  5249. currentStatus = Unavailable; //OCPP Status : Unavailable
  5250. }
  5251. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5252. {
  5253. currentStatus = Faulted; //OCPP Status: Faulted
  5254. }
  5255. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5256. {
  5257. currentStatus = Reserved; //OCPP Status: Reserved
  5258. }
  5259. } //end of the same index
  5260. } // end of for CCS_QUANTITY
  5261. }
  5262. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5263. {
  5264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5265. {
  5266. tempIndex = ((gun_index==2) ? 1: 0);
  5267. }
  5268. else
  5269. {
  5270. tempIndex = gun_index;
  5271. }
  5272. for (int index = 0; index < GB_QUANTITY; index++)
  5273. {
  5274. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5275. {
  5276. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5277. {
  5278. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5279. {
  5280. currentStatus = Preparing; //OCPP Status: Preparing
  5281. }
  5282. else
  5283. {
  5284. currentStatus = Available; //OCPP Status: Available
  5285. }
  5286. }
  5287. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5288. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5289. ) //S_PRECHARGE
  5290. {
  5291. currentStatus = Preparing; //OCPP Status: Preparing
  5292. }
  5293. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5294. {
  5295. currentStatus = Charging; //OCPP Status: Charging
  5296. }
  5297. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5298. {
  5299. currentStatus = Finishing; //OCPP Status: Finishing
  5300. }
  5301. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5302. {
  5303. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5304. }
  5305. 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
  5306. {
  5307. currentStatus = Unavailable; //OCPP Status: Unavailable
  5308. }
  5309. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5310. {
  5311. currentStatus = Faulted; //OCPP Status: Faulted
  5312. }
  5313. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5314. {
  5315. currentStatus = Reserved; //OCPP Status: Reserved
  5316. }
  5317. } //end of the same index
  5318. } // end of for GB_QUANTITY
  5319. }
  5320. else if(gunType[gun_index] == GUN_TYPE_DO)
  5321. {
  5322. tempIndex = gun_index;
  5323. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5324. {
  5325. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5326. {
  5327. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5328. {
  5329. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5330. {
  5331. currentStatus = Preparing; //OCPP Status: Preparing
  5332. }
  5333. else
  5334. {
  5335. currentStatus = Available; //OCPP Status: Available
  5336. }
  5337. }
  5338. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5339. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5340. ) //S_PRECHARGE
  5341. {
  5342. currentStatus = Preparing; //OCPP Status: Preparing
  5343. }
  5344. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5345. {
  5346. currentStatus = Charging; //OCPP Status: Charging
  5347. }
  5348. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5349. {
  5350. currentStatus = Finishing; //OCPP Status: Finishing
  5351. }
  5352. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5353. {
  5354. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5355. }
  5356. 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
  5357. {
  5358. currentStatus = Unavailable; //OCPP Status: Unavailable
  5359. }
  5360. 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
  5361. {
  5362. currentStatus = Faulted; //OCPP Status: Faulted
  5363. }
  5364. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5365. {
  5366. currentStatus = Reserved; //OCPP Status: Reserved
  5367. }
  5368. } //end of the same index
  5369. }
  5370. }
  5371. else
  5372. {
  5373. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5374. {
  5375. tempIndex = 2;
  5376. }
  5377. else
  5378. {
  5379. tempIndex = gun_index;
  5380. }
  5381. for (int index = 0; index < AC_QUANTITY; index++)
  5382. {
  5383. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5384. {
  5385. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5386. {
  5387. 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))
  5388. {
  5389. currentStatus = Preparing; //OCPP Status: Preparing
  5390. }
  5391. else
  5392. {
  5393. currentStatus = Available; //OCPP Status: Available
  5394. }
  5395. }
  5396. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5397. {
  5398. currentStatus = Preparing; //OCPP Status: Preparing
  5399. }
  5400. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5401. {
  5402. currentStatus = Charging; //OCPP Status: Charging
  5403. }
  5404. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5405. {
  5406. currentStatus = Finishing; //OCPP Status: Finishing
  5407. }
  5408. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5409. {
  5410. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5411. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5412. else
  5413. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5414. }
  5415. 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
  5416. {
  5417. currentStatus = Unavailable; //OCPP Status: Unavailable
  5418. }
  5419. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5420. {
  5421. currentStatus = Faulted; //OCPP Status: Faulted
  5422. }
  5423. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5424. {
  5425. currentStatus = Reserved; //OCPP Status: Reserved
  5426. }
  5427. }//end of the same index
  5428. }//end of for AC_QUANTITY
  5429. }
  5430. //it's option
  5431. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5432. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5433. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5434. {
  5435. isStateChanged = FALSE;
  5436. }
  5437. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5438. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5439. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5440. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5441. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5442. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5443. isContentIllegal = TRUE;
  5444. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5445. {
  5446. if(strcmp((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5447. {
  5448. isContentIllegal = FALSE;
  5449. break;
  5450. }
  5451. }
  5452. if(isContentIllegal)
  5453. {
  5454. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5455. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5456. }
  5457. random_uuid(guid);
  5458. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5459. , MESSAGE_TYPE_CALL
  5460. , guid
  5461. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5462. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5463. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5464. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5465. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5466. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5467. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5468. if((server_sign == TRUE) && isStateChanged)
  5469. {
  5470. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5471. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5472. LWS_Send(message);
  5473. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5474. 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*/)
  5475. {
  5476. //DEBUG_ERROR("statusNotification mapitem pass");
  5477. result = PASS;
  5478. }
  5479. }
  5480. else
  5481. {
  5482. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5483. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5484. result = PASS;
  5485. }
  5486. return result;
  5487. }
  5488. int sendStopTransactionRequest(int gun_index)
  5489. {
  5490. mtrace();
  5491. int result = FAIL;
  5492. //char message[1500]={0};
  5493. char guid[37]={0};
  5494. char tempdata[65]={0};
  5495. int tempIndex = 0;
  5496. char TempStopTransaction[256];
  5497. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5498. //int idx_sample=0;
  5499. DEBUG_INFO("sendStopTransactionRequest \n");
  5500. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5501. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5502. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5503. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5504. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5505. {
  5506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5507. {
  5508. tempIndex = ((gun_index==2) ? 1: 0);
  5509. }
  5510. else
  5511. {
  5512. tempIndex = gun_index;
  5513. }
  5514. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5515. {
  5516. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5517. {
  5518. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5519. }
  5520. }// END OF CHAdeMO_QUANTITY
  5521. }
  5522. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5523. {
  5524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5525. {
  5526. tempIndex = ((gun_index==2) ? 1: 0);
  5527. }
  5528. else
  5529. {
  5530. tempIndex = gun_index;
  5531. }
  5532. for (int index = 0; index < CCS_QUANTITY; index++)
  5533. {
  5534. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5535. {
  5536. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5537. }
  5538. }// END OF CCS_QUANTITY
  5539. }
  5540. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5541. {
  5542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5543. {
  5544. tempIndex = ((gun_index==2) ? 1: 0);
  5545. }
  5546. else
  5547. {
  5548. tempIndex = gun_index;
  5549. }
  5550. for (int index = 0; index < GB_QUANTITY; index++)
  5551. {
  5552. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5553. {
  5554. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5555. }
  5556. }// END OF GB_QUANTITY
  5557. }
  5558. else if(gunType[gun_index] == GUN_TYPE_DO)
  5559. {
  5560. tempIndex = gun_index;
  5561. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5562. {
  5563. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5564. {
  5565. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5566. }
  5567. }// END OF GB_QUANTITY
  5568. }
  5569. else
  5570. {
  5571. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5572. {
  5573. tempIndex = 2;
  5574. }
  5575. else
  5576. {
  5577. tempIndex = gun_index;
  5578. }
  5579. for (int index = 0; index < AC_QUANTITY; index++)
  5580. {
  5581. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5582. {
  5583. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5584. }
  5585. }// END OF AC_QUANTITY
  5586. }
  5587. //====================================== Stop Transaction Time =====================================================
  5588. struct timeval tmnow;
  5589. struct tm *tm;
  5590. char buf[28];//, usec_buf[6];
  5591. gettimeofday(&tmnow, NULL);
  5592. time_t t;
  5593. t = time(NULL);
  5594. /*UTC time and date*/
  5595. tm = gmtime(&t);
  5596. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5598. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5599. random_uuid(guid);
  5600. /***********************************transactionData******************************************************/
  5601. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5602. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5603. //=================================
  5604. // Transaction_Begin
  5605. //=================================
  5606. //=================================
  5607. // Transaction_End
  5608. //=================================
  5609. // ================================= Current.Import L1 ===============================================
  5610. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5611. {
  5612. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5613. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5614. {
  5615. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5616. {
  5617. tempIndex = ((gun_index==2) ? 1: 0);
  5618. }
  5619. else
  5620. {
  5621. tempIndex = gun_index;
  5622. }
  5623. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5624. {
  5625. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5626. {
  5627. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5628. }
  5629. }// End of for CHAdeMO_QUANTITY
  5630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5631. }
  5632. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5633. {
  5634. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5635. {
  5636. tempIndex = ((gun_index==2) ? 1: 0);
  5637. }
  5638. else
  5639. {
  5640. tempIndex = gun_index;
  5641. }
  5642. for (int index = 0; index < CCS_QUANTITY; index++)
  5643. {
  5644. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5645. {
  5646. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5647. }
  5648. }// End of for CCS_QUANTITY
  5649. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5650. }
  5651. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5652. {
  5653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5654. {
  5655. tempIndex = ((gun_index==2) ? 1: 0);
  5656. }
  5657. else
  5658. {
  5659. tempIndex = gun_index;
  5660. }
  5661. for (int index = 0; index < GB_QUANTITY; index++)
  5662. {
  5663. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5664. {
  5665. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5666. }
  5667. }// End of for GB_QUANTITY
  5668. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5669. }
  5670. else if(gunType[gun_index] == GUN_TYPE_DO)
  5671. {
  5672. tempIndex = gun_index;
  5673. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5674. {
  5675. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5676. {
  5677. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5678. }
  5679. }
  5680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5681. }
  5682. else
  5683. {
  5684. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5685. {
  5686. tempIndex = 2;
  5687. }
  5688. else
  5689. {
  5690. tempIndex = gun_index;
  5691. }
  5692. for (int index = 0; index < AC_QUANTITY; index++)
  5693. {
  5694. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5695. {
  5696. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5697. }
  5698. }// End of for AC_QUANTITY
  5699. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5700. }
  5701. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5702. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5703. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5704. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5705. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5706. }
  5707. // ================================= Energy.Active.Import.Interval ==============================================
  5708. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5709. {
  5710. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5711. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5712. {
  5713. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5714. {
  5715. tempIndex = ((gun_index==2) ? 1: 0);
  5716. }
  5717. else
  5718. {
  5719. tempIndex = gun_index;
  5720. }
  5721. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5722. {
  5723. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5724. {
  5725. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5726. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5727. }
  5728. }// END OF CHAdeMO_QUANTITY
  5729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5730. }
  5731. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5732. {
  5733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5734. {
  5735. tempIndex = ((gun_index==2) ? 1: 0);
  5736. }
  5737. else
  5738. {
  5739. tempIndex = gun_index;
  5740. }
  5741. for (int index = 0; index < CCS_QUANTITY; index++)
  5742. {
  5743. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5744. {
  5745. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5746. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5747. }
  5748. }// END OF CCS_QUANTITY
  5749. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5750. }
  5751. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5752. {
  5753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5754. {
  5755. tempIndex = ((gun_index==2) ? 1: 0);
  5756. }
  5757. else
  5758. {
  5759. tempIndex = gun_index;
  5760. }
  5761. for (int index = 0; index < GB_QUANTITY; index++)
  5762. {
  5763. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5764. {
  5765. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5766. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5767. }
  5768. }// END OF GB_QUANTITY
  5769. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5770. }
  5771. else if(gunType[gun_index] == GUN_TYPE_DO)
  5772. {
  5773. tempIndex = gun_index;
  5774. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5775. {
  5776. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5777. {
  5778. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5779. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5780. }
  5781. }
  5782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5783. }
  5784. else
  5785. {
  5786. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5787. {
  5788. tempIndex = 2;
  5789. }
  5790. else
  5791. {
  5792. tempIndex = gun_index;
  5793. }
  5794. for (int index = 0; index < AC_QUANTITY; index++)
  5795. {
  5796. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5797. {
  5798. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5799. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5800. }
  5801. }// END OF AC_QUANTITY
  5802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5803. }
  5804. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5806. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5809. }
  5810. //=================================== Power.Active.Import ==================================================
  5811. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5812. {
  5813. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5814. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5815. {
  5816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5817. {
  5818. tempIndex = ((gun_index==2) ? 1: 0);
  5819. }
  5820. else
  5821. {
  5822. tempIndex = gun_index;
  5823. }
  5824. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5825. {
  5826. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5827. {
  5828. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5829. }
  5830. } // End for CHAdeMO_QUANTITY
  5831. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5832. }
  5833. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5834. {
  5835. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5836. {
  5837. tempIndex = ((gun_index==2) ? 1: 0);
  5838. }
  5839. else
  5840. {
  5841. tempIndex = gun_index;
  5842. }
  5843. for (int index = 0; index < CCS_QUANTITY; index++)
  5844. {
  5845. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5846. {
  5847. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5848. }
  5849. } // END for CCS_QUANTITY
  5850. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5851. }
  5852. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5853. {
  5854. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5855. {
  5856. tempIndex = ((gun_index==2) ? 1: 0);
  5857. }
  5858. else
  5859. {
  5860. tempIndex = gun_index;
  5861. }
  5862. for (int index = 0; index < GB_QUANTITY; index++)
  5863. {
  5864. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5865. {
  5866. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5867. }
  5868. }// END for GB_QUANTITY
  5869. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5870. }
  5871. else if(gunType[gun_index] == GUN_TYPE_DO)
  5872. {
  5873. tempIndex = gun_index;
  5874. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5875. {
  5876. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5877. {
  5878. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5879. }
  5880. }
  5881. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5882. }
  5883. else
  5884. {
  5885. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5886. {
  5887. tempIndex = 2;
  5888. }
  5889. else
  5890. {
  5891. tempIndex = gun_index;
  5892. }
  5893. for (int index = 0; index < AC_QUANTITY; index++)
  5894. {
  5895. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5896. {
  5897. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5898. }
  5899. } // END for AC_QUANTITY
  5900. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5901. }
  5902. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5903. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5904. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5905. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5906. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5907. }
  5908. //============================ Voltage L1 ====================================
  5909. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5910. {
  5911. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5912. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5913. {
  5914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5915. {
  5916. tempIndex = ((gun_index==2) ? 1: 0);
  5917. }
  5918. else
  5919. {
  5920. tempIndex = gun_index;
  5921. }
  5922. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5923. {
  5924. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5925. {
  5926. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5927. }
  5928. } // END OF FOR CHAdeMO_QUANTITY
  5929. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5930. }
  5931. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5932. {
  5933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5934. {
  5935. tempIndex = ((gun_index==2) ? 1: 0);
  5936. }
  5937. else
  5938. {
  5939. tempIndex = gun_index;
  5940. }
  5941. for (int index = 0; index < CCS_QUANTITY; index++)
  5942. {
  5943. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5944. {
  5945. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5946. }
  5947. } // END OF FOR CCS_QUANTITY
  5948. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5949. }
  5950. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5951. {
  5952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5953. {
  5954. tempIndex = ((gun_index==2) ? 1: 0);
  5955. }
  5956. else
  5957. {
  5958. tempIndex = gun_index;
  5959. }
  5960. for (int index = 0; index < GB_QUANTITY; index++)
  5961. {
  5962. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5963. {
  5964. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5965. }
  5966. } // END OF FOR GB_QUANTITY
  5967. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5968. }
  5969. else if(gunType[gun_index] == GUN_TYPE_DO)
  5970. {
  5971. tempIndex = gun_index;
  5972. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5973. {
  5974. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5975. {
  5976. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5977. }
  5978. }
  5979. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5980. }
  5981. else
  5982. {
  5983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5984. {
  5985. tempIndex = 2;
  5986. }
  5987. else
  5988. {
  5989. tempIndex = gun_index;
  5990. }
  5991. for (int index = 0; index < AC_QUANTITY; index++)
  5992. {
  5993. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5994. {
  5995. 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
  5996. }
  5997. } // END OF FOR AC_QUANTITY
  5998. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5999. }
  6000. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6002. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6003. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6004. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6005. }
  6006. //====================== End SoC ================================
  6007. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6008. {
  6009. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6010. 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))
  6011. {
  6012. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6013. {
  6014. tempIndex = ((gun_index==2) ? 1: 0);
  6015. }
  6016. else
  6017. {
  6018. tempIndex = gun_index;
  6019. }
  6020. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6021. {
  6022. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6023. {
  6024. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6025. {
  6026. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6027. }
  6028. }
  6029. }
  6030. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6031. {
  6032. for (int index = 0; index < CCS_QUANTITY; index++)
  6033. {
  6034. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6035. {
  6036. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6037. }
  6038. }
  6039. }
  6040. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6041. {
  6042. for (int index = 0; index < GB_QUANTITY; index++)
  6043. {
  6044. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6045. {
  6046. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6047. }
  6048. }
  6049. }
  6050. else if(gunType[gun_index] == GUN_TYPE_DO)
  6051. {
  6052. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6053. {
  6054. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6055. {
  6056. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6057. }
  6058. }
  6059. }
  6060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6061. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6062. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6063. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6064. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6065. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6066. } // END FOR DC CASE
  6067. }
  6068. // ================================= Current.Import L2 ===============================================
  6069. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6070. {
  6071. // AC 3 phse L2 current
  6072. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6073. {
  6074. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6075. {
  6076. tempIndex = 2;
  6077. }
  6078. else
  6079. {
  6080. tempIndex = gun_index;
  6081. }
  6082. for (int index = 0; index < AC_QUANTITY; index++)
  6083. {
  6084. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6085. {
  6086. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6087. }
  6088. }// End of for AC_QUANTITY
  6089. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6090. }
  6091. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6092. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6093. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6094. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6095. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6096. }
  6097. // ================================= Current.Import L3 ===============================================
  6098. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6099. {
  6100. // AC 3 phse L3 current
  6101. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6102. {
  6103. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6104. {
  6105. tempIndex = 2;
  6106. }
  6107. else
  6108. {
  6109. tempIndex = gun_index;
  6110. }
  6111. for (int index = 0; index < AC_QUANTITY; index++)
  6112. {
  6113. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6114. {
  6115. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6116. }
  6117. }// End of for AC_QUANTITY
  6118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6119. }
  6120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6121. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6122. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6123. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6124. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6125. }
  6126. //============================ Voltage L2 ====================================
  6127. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6128. {
  6129. // AC 3 phse L2 voltage
  6130. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6131. {
  6132. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6133. {
  6134. tempIndex = 2;
  6135. }
  6136. else
  6137. {
  6138. tempIndex = gun_index;
  6139. }
  6140. for (int index = 0; index < AC_QUANTITY; index++)
  6141. {
  6142. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6143. {
  6144. 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
  6145. }
  6146. } // END OF FOR AC_QUANTITY
  6147. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6148. }
  6149. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6150. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6151. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6152. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6153. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6154. }
  6155. //============================ Voltage L3 ====================================
  6156. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6157. {
  6158. // AC 3 phse L3 voltage
  6159. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6160. {
  6161. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6162. {
  6163. tempIndex = 2;
  6164. }
  6165. else
  6166. {
  6167. tempIndex = gun_index;
  6168. }
  6169. for (int index = 0; index < AC_QUANTITY; index++)
  6170. {
  6171. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6172. {
  6173. 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
  6174. }
  6175. } // END OF FOR AC_QUANTITY
  6176. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6177. }
  6178. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6179. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6180. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6181. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6182. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6183. }
  6184. //====================== Start SoC ================================
  6185. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6186. {
  6187. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6188. 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))
  6189. {
  6190. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6191. {
  6192. tempIndex = ((gun_index==2) ? 1: 0);
  6193. }
  6194. else
  6195. {
  6196. tempIndex = gun_index;
  6197. }
  6198. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6199. {
  6200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6201. {
  6202. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6203. {
  6204. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6205. }
  6206. }
  6207. }
  6208. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6209. {
  6210. for (int index = 0; index < CCS_QUANTITY; index++)
  6211. {
  6212. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6213. {
  6214. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6215. }
  6216. }
  6217. }
  6218. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6219. {
  6220. for (int index = 0; index < GB_QUANTITY; index++)
  6221. {
  6222. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6223. {
  6224. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6225. }
  6226. }
  6227. }
  6228. else if(gunType[gun_index] == GUN_TYPE_DO)
  6229. {
  6230. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6231. {
  6232. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6233. {
  6234. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6235. }
  6236. }
  6237. }
  6238. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6239. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6240. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6241. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6242. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6243. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6244. } // END FOR DC CASE
  6245. }
  6246. //================================================ Message create ====================================================
  6247. json_object *StopTransaction = json_object_new_object();
  6248. json_object *transactionDatas = json_object_new_array();
  6249. json_object *sampledValues = json_object_new_array();
  6250. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6251. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6252. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6253. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6254. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6255. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6256. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6257. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6258. {
  6259. json_object *transactionData = json_object_new_object();
  6260. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6261. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6262. {
  6263. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6264. {
  6265. json_object *sampledValue = json_object_new_object();
  6266. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6267. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6268. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6269. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6270. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6271. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6272. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6273. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6274. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6275. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6276. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6277. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6278. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6279. json_object_array_add(sampledValues, sampledValue);
  6280. }
  6281. }
  6282. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6283. json_object_array_add(transactionDatas, transactionData);
  6284. }
  6285. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6286. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6287. ,MESSAGE_TYPE_CALL
  6288. ,guid
  6289. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6290. json_object_put(StopTransaction);
  6291. #if 1 // for TempStopTransaction
  6292. //Delete TempStopTransaction
  6293. if((access(TempStopTransaction,F_OK))!=-1)
  6294. {
  6295. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6296. }
  6297. #endif
  6298. #if 1
  6299. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6300. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6301. {
  6302. result = PASS;
  6303. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6304. }
  6305. #endif
  6306. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6307. OCPP_insert_transaction_msg(NO, queuedata);
  6308. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6309. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6310. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6311. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6312. {
  6313. //SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6314. }
  6315. //for test
  6316. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6317. return result;
  6318. }
  6319. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6320. {
  6321. mtrace();
  6322. int result = FAIL;
  6323. char guid[37]={0};
  6324. char tempdata[65]={0};
  6325. int tempIndex = 0;
  6326. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6327. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6328. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6329. //set value
  6330. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6331. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6332. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6333. -1);
  6334. random_uuid(guid);
  6335. //UTC Date time
  6336. struct timeval tmnow;
  6337. struct tm *tm;
  6338. char buf[28];//, usec_buf[6];
  6339. gettimeofday(&tmnow, NULL);
  6340. time_t t;
  6341. t = time(NULL);
  6342. /*UTC time and date*/
  6343. tm = gmtime(&t);
  6344. if(dataType == ReadingContext_Sample_Clock)
  6345. {
  6346. struct tm *tmTarget;
  6347. struct timeb tbTarget;
  6348. tbTarget.time = mktime(tm);
  6349. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6350. tmTarget = gmtime(&tbTarget.time);
  6351. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6352. }
  6353. else
  6354. {
  6355. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6356. }
  6357. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6358. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6359. //********************************(1)Current.Import L1************************************************/
  6360. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6361. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6362. (dataType == ReadingContext_Trigger))
  6363. {
  6364. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6365. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6366. {
  6367. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6368. {
  6369. tempIndex = ((gun_index==2) ? 1: 0);
  6370. }
  6371. else
  6372. {
  6373. tempIndex = gun_index;
  6374. }
  6375. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6376. {
  6377. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6378. {
  6379. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6380. }
  6381. }
  6382. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6383. }
  6384. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6385. {
  6386. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6387. {
  6388. tempIndex = ((gun_index==2) ? 1: 0);
  6389. }
  6390. else
  6391. {
  6392. tempIndex = gun_index;
  6393. }
  6394. for (int index = 0; index < CCS_QUANTITY; index++)
  6395. {
  6396. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6397. {
  6398. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6399. }
  6400. }
  6401. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6402. }
  6403. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6404. {
  6405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6406. {
  6407. tempIndex = ((gun_index==2) ? 1: 0);
  6408. }
  6409. else
  6410. {
  6411. tempIndex = gun_index;
  6412. }
  6413. for (int index = 0; index < GB_QUANTITY; index++)
  6414. {
  6415. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6416. {
  6417. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6418. }
  6419. }
  6420. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6421. }
  6422. else if(gunType[gun_index] == GUN_TYPE_DO)
  6423. {
  6424. tempIndex = gun_index;
  6425. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6426. {
  6427. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6428. {
  6429. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6430. }
  6431. }
  6432. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6433. }
  6434. else
  6435. {
  6436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6437. {
  6438. tempIndex = 2;
  6439. }
  6440. else
  6441. {
  6442. tempIndex = gun_index;
  6443. }
  6444. for (int index = 0; index < AC_QUANTITY; index++)
  6445. {
  6446. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6447. {
  6448. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6449. }
  6450. }
  6451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6452. }
  6453. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6454. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6455. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6456. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6457. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6458. }
  6459. //********************************(2)Energy.Active.Import.Register ************************************************/
  6460. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6461. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6462. (dataType == ReadingContext_Trigger))
  6463. {
  6464. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6465. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6466. {
  6467. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6468. {
  6469. tempIndex = ((gun_index==2) ? 1: 0);
  6470. }
  6471. else
  6472. {
  6473. tempIndex = gun_index;
  6474. }
  6475. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6476. {
  6477. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6478. {
  6479. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6480. }
  6481. }
  6482. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6483. }
  6484. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6485. {
  6486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6487. {
  6488. tempIndex = ((gun_index==2) ? 1: 0);
  6489. }
  6490. else
  6491. {
  6492. tempIndex = gun_index;
  6493. }
  6494. for (int index = 0; index < CCS_QUANTITY; index++)
  6495. {
  6496. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6497. {
  6498. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6499. }
  6500. }
  6501. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6502. }
  6503. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6504. {
  6505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6506. {
  6507. tempIndex = ((gun_index==2) ? 1: 0);
  6508. }
  6509. else
  6510. {
  6511. tempIndex = gun_index;
  6512. }
  6513. for (int index = 0; index < GB_QUANTITY; index++)
  6514. {
  6515. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6516. {
  6517. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6518. }
  6519. }
  6520. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6521. }
  6522. else if(gunType[gun_index] == GUN_TYPE_DO)
  6523. {
  6524. tempIndex = gun_index;
  6525. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6526. {
  6527. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6528. {
  6529. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6530. }
  6531. }
  6532. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6533. }
  6534. else
  6535. {
  6536. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6537. {
  6538. tempIndex = 2;
  6539. }
  6540. else
  6541. {
  6542. tempIndex = gun_index;
  6543. }
  6544. for (int index = 0; index < AC_QUANTITY; index++)
  6545. {
  6546. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6547. {
  6548. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6549. }
  6550. }
  6551. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6552. }
  6553. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6554. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6555. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6556. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6557. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6558. }
  6559. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6560. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6561. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6562. (dataType == ReadingContext_Trigger))
  6563. {
  6564. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6565. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6566. {
  6567. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6568. {
  6569. tempIndex = ((gun_index==2) ? 1: 0);
  6570. }
  6571. else
  6572. {
  6573. tempIndex = gun_index;
  6574. }
  6575. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6576. {
  6577. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6578. {
  6579. if(dataType == ReadingContext_Sample_Clock)
  6580. {
  6581. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6582. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6583. }
  6584. else if(dataType == ReadingContext_Sample_Periodic)
  6585. {
  6586. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6587. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6588. }
  6589. else
  6590. {
  6591. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6592. }
  6593. }
  6594. } // END OF FOR CHAdeMO_QUANTITY
  6595. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6596. }
  6597. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6598. {
  6599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6600. {
  6601. tempIndex = ((gun_index==2) ? 1: 0);
  6602. }
  6603. else
  6604. {
  6605. tempIndex = gun_index;
  6606. }
  6607. for (int index = 0; index < CCS_QUANTITY; index++)
  6608. {
  6609. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6610. {
  6611. if(dataType == ReadingContext_Sample_Clock)
  6612. {
  6613. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6614. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6615. }
  6616. else if(dataType == ReadingContext_Sample_Periodic)
  6617. {
  6618. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6619. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6620. }
  6621. else
  6622. {
  6623. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6624. }
  6625. }
  6626. } // END OF CCS_QUANTITY
  6627. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6628. }
  6629. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6630. {
  6631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6632. {
  6633. tempIndex = ((gun_index==2) ? 1: 0);
  6634. }
  6635. else
  6636. {
  6637. tempIndex = gun_index;
  6638. }
  6639. for (int index = 0; index < GB_QUANTITY; index++)
  6640. {
  6641. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6642. {
  6643. if(dataType == ReadingContext_Sample_Clock)
  6644. {
  6645. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6646. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6647. }
  6648. else if(dataType == ReadingContext_Sample_Periodic)
  6649. {
  6650. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6651. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6652. }
  6653. else
  6654. {
  6655. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6656. }
  6657. }
  6658. } // END OF GB_QUANTITY
  6659. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6660. }
  6661. else if(gunType[gun_index] == GUN_TYPE_DO)
  6662. {
  6663. tempIndex = gun_index;
  6664. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6665. {
  6666. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6667. {
  6668. if(dataType == ReadingContext_Sample_Clock)
  6669. {
  6670. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  6671. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6672. }
  6673. else if(dataType == ReadingContext_Sample_Periodic)
  6674. {
  6675. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6676. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6677. }
  6678. else
  6679. {
  6680. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6681. }
  6682. }
  6683. }
  6684. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6685. }
  6686. else
  6687. {
  6688. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6689. {
  6690. tempIndex = 2;
  6691. }
  6692. else
  6693. {
  6694. tempIndex = gun_index;
  6695. }
  6696. for (int index = 0; index < AC_QUANTITY; index++)
  6697. {
  6698. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6699. {
  6700. if(dataType == ReadingContext_Sample_Clock)
  6701. {
  6702. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6703. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6704. }
  6705. else if(dataType == ReadingContext_Sample_Periodic)
  6706. {
  6707. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6708. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6709. }
  6710. else
  6711. {
  6712. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6713. }
  6714. }
  6715. }
  6716. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6717. }
  6718. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6719. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6720. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6721. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6722. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6723. }
  6724. //********************************(4)Power.Active.Import************************************************/
  6725. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6726. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6727. (dataType == ReadingContext_Trigger))
  6728. {
  6729. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6730. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6731. {
  6732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6733. {
  6734. tempIndex = ((gun_index==2) ? 1: 0);
  6735. }
  6736. else
  6737. {
  6738. tempIndex = gun_index;
  6739. }
  6740. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6741. {
  6742. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6743. {
  6744. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6745. }
  6746. } // END OF FOR
  6747. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6748. }
  6749. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6750. {
  6751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6752. {
  6753. tempIndex = ((gun_index==2) ? 1: 0);
  6754. }
  6755. else
  6756. {
  6757. tempIndex = gun_index;
  6758. }
  6759. for (int index = 0; index < CCS_QUANTITY; index++)
  6760. {
  6761. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6762. {
  6763. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6764. }
  6765. }
  6766. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6767. }
  6768. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6769. {
  6770. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6771. {
  6772. tempIndex = ((gun_index==2) ? 1: 0);
  6773. }
  6774. else
  6775. {
  6776. tempIndex = gun_index;
  6777. }
  6778. for (int index = 0; index < GB_QUANTITY; index++)
  6779. {
  6780. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6781. {
  6782. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6783. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6784. }
  6785. }
  6786. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6787. }
  6788. else if(gunType[gun_index] == GUN_TYPE_DO)
  6789. {
  6790. tempIndex = gun_index;
  6791. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6792. {
  6793. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6794. {
  6795. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6796. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6797. }
  6798. }
  6799. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6800. }
  6801. else
  6802. {
  6803. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6804. {
  6805. tempIndex = 2;
  6806. }
  6807. else
  6808. {
  6809. tempIndex = gun_index;
  6810. }
  6811. for (int index = 0; index < AC_QUANTITY; index++)
  6812. {
  6813. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6814. {
  6815. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6816. }
  6817. }
  6818. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6819. }
  6820. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6821. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6822. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6823. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6824. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6825. }
  6826. //***********************************************(5)VOLTAGE L1******************************************************/
  6827. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6828. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6829. (dataType == ReadingContext_Trigger))
  6830. {
  6831. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6832. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6833. {
  6834. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6835. {
  6836. tempIndex = ((gun_index==2) ? 1: 0);
  6837. }
  6838. else
  6839. {
  6840. tempIndex = gun_index;
  6841. }
  6842. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6843. {
  6844. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6845. {
  6846. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6847. }
  6848. }
  6849. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6850. }
  6851. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6852. {
  6853. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6854. {
  6855. tempIndex = ((gun_index==2) ? 1: 0);
  6856. }
  6857. else
  6858. {
  6859. tempIndex = gun_index;
  6860. }
  6861. for (int index = 0; index < CCS_QUANTITY; index++)
  6862. {
  6863. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6864. {
  6865. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6866. }
  6867. }
  6868. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6869. }
  6870. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6871. {
  6872. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6873. {
  6874. tempIndex = ((gun_index==2) ? 1: 0);
  6875. }
  6876. else
  6877. {
  6878. tempIndex = gun_index;
  6879. }
  6880. for (int index = 0; index < GB_QUANTITY; index++)
  6881. {
  6882. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6883. {
  6884. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6885. }
  6886. }
  6887. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6888. }
  6889. else if(gunType[gun_index] == GUN_TYPE_DO)
  6890. {
  6891. tempIndex = gun_index;
  6892. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6893. {
  6894. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6895. {
  6896. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6897. }
  6898. }
  6899. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6900. }
  6901. else
  6902. {
  6903. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6904. {
  6905. tempIndex = 2;
  6906. }
  6907. else
  6908. {
  6909. tempIndex = gun_index;
  6910. }
  6911. for (int index = 0; index < AC_QUANTITY; index++)
  6912. {
  6913. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6914. {
  6915. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6916. }
  6917. }
  6918. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6919. }
  6920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6921. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6922. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6923. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6924. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6925. }
  6926. //***********************************************(6)SOC******************************************************/
  6927. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6928. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6929. (dataType == ReadingContext_Trigger))
  6930. {
  6931. 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))
  6932. {
  6933. //idx_sample=5;
  6934. //sampledValue = NULL;
  6935. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6936. {
  6937. tempIndex = ((gun_index==2) ? 1: 0);
  6938. }
  6939. else
  6940. {
  6941. tempIndex = gun_index;
  6942. }
  6943. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6944. {
  6945. //tempIndex = ((gun_index==2) ? 1: 0);
  6946. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6947. {
  6948. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6949. {
  6950. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6951. }
  6952. }
  6953. }
  6954. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6955. {
  6956. //tempIndex = ((gun_index==2) ? 1: 0);
  6957. for (int index = 0; index < CCS_QUANTITY; index++)
  6958. {
  6959. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6960. {
  6961. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6962. }
  6963. }
  6964. }
  6965. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6966. {
  6967. //tempIndex = ((gun_index==2) ? 1: 0);
  6968. for (int index = 0; index < GB_QUANTITY; index++)
  6969. {
  6970. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6971. {
  6972. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6973. }
  6974. }
  6975. }
  6976. else if(gunType[gun_index] == GUN_TYPE_DO)
  6977. {
  6978. //tempIndex = ((gun_index==2) ? 1: 0);
  6979. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6980. {
  6981. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6982. {
  6983. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6984. }
  6985. }
  6986. }
  6987. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6988. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6989. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6990. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6991. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6992. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6993. }
  6994. }
  6995. //********************************(7)Current.Import L2************************************************/
  6996. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6997. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6998. (dataType == ReadingContext_Trigger))
  6999. {
  7000. // Only for AC 3 phase
  7001. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7002. {
  7003. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7004. {
  7005. tempIndex = 2;
  7006. }
  7007. else
  7008. {
  7009. tempIndex = gun_index;
  7010. }
  7011. for (int index = 0; index < AC_QUANTITY; index++)
  7012. {
  7013. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7014. {
  7015. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7016. }
  7017. }
  7018. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7019. }
  7020. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7021. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7022. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7023. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7024. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7025. }
  7026. //********************************(8)Current.Import L3************************************************/
  7027. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7028. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7029. (dataType == ReadingContext_Trigger))
  7030. {
  7031. // Only for AC 3 phase
  7032. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7033. {
  7034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7035. {
  7036. tempIndex = 2;
  7037. }
  7038. else
  7039. {
  7040. tempIndex = gun_index;
  7041. }
  7042. for (int index = 0; index < AC_QUANTITY; index++)
  7043. {
  7044. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7045. {
  7046. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7047. }
  7048. }
  7049. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7050. }
  7051. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7052. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7053. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7054. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7055. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7056. }
  7057. //***********************************************(9)VOLTAGE L2******************************************************/
  7058. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7059. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7060. (dataType == ReadingContext_Trigger))
  7061. {
  7062. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7063. {
  7064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7065. {
  7066. tempIndex = 2;
  7067. }
  7068. else
  7069. {
  7070. tempIndex = gun_index;
  7071. }
  7072. for (int index = 0; index < AC_QUANTITY; index++)
  7073. {
  7074. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7075. {
  7076. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7077. }
  7078. }
  7079. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7080. }
  7081. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7082. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7083. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7084. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7085. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7086. }
  7087. //***********************************************(10)VOLTAGE L3******************************************************/
  7088. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7089. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7090. (dataType == ReadingContext_Trigger))
  7091. {
  7092. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7093. {
  7094. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7095. {
  7096. tempIndex = 2;
  7097. }
  7098. else
  7099. {
  7100. tempIndex = gun_index;
  7101. }
  7102. for (int index = 0; index < AC_QUANTITY; index++)
  7103. {
  7104. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7105. {
  7106. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7107. }
  7108. }
  7109. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7110. }
  7111. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7112. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7113. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7114. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7115. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7116. }
  7117. //***********************************************(11)Current.Offered******************************************************/
  7118. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7119. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7120. (dataType == ReadingContext_Trigger))
  7121. {
  7122. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7123. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7124. {
  7125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7126. {
  7127. tempIndex = ((gun_index==2) ? 1: 0);
  7128. }
  7129. else
  7130. {
  7131. tempIndex = gun_index;
  7132. }
  7133. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7134. {
  7135. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7136. {
  7137. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  7138. }
  7139. } // END OF FOR CHAdeMO_QUANTITY
  7140. }
  7141. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7142. {
  7143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7144. {
  7145. tempIndex = ((gun_index==2) ? 1: 0);
  7146. }
  7147. else
  7148. {
  7149. tempIndex = gun_index;
  7150. }
  7151. for (int index = 0; index < CCS_QUANTITY; index++)
  7152. {
  7153. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7154. {
  7155. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  7156. }
  7157. } // END OF CCS_QUANTITY
  7158. }
  7159. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7160. {
  7161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7162. {
  7163. tempIndex = ((gun_index==2) ? 1: 0);
  7164. }
  7165. else
  7166. {
  7167. tempIndex = gun_index;
  7168. }
  7169. for (int index = 0; index < GB_QUANTITY; index++)
  7170. {
  7171. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7172. {
  7173. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  7174. }
  7175. } // END OF GB_QUANTITY
  7176. }
  7177. else if(gunType[gun_index] == GUN_TYPE_DO)
  7178. {
  7179. tempIndex = gun_index;
  7180. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7181. {
  7182. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7183. {
  7184. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  7185. }
  7186. }
  7187. }
  7188. else
  7189. {
  7190. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7191. {
  7192. tempIndex = 2;
  7193. }
  7194. else
  7195. {
  7196. tempIndex = gun_index;
  7197. }
  7198. for (int index = 0; index < AC_QUANTITY; index++)
  7199. {
  7200. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7201. {
  7202. uint16_t currentOffer;
  7203. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7204. {
  7205. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7206. }
  7207. else
  7208. {
  7209. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7210. }
  7211. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7212. }
  7213. }
  7214. }
  7215. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7216. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7217. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7218. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7219. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7220. }
  7221. //***********************************************(12)Power.Offered******************************************************/
  7222. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7223. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7224. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7225. {
  7226. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7227. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7228. {
  7229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7230. {
  7231. tempIndex = ((gun_index==2) ? 1: 0);
  7232. }
  7233. else
  7234. {
  7235. tempIndex = gun_index;
  7236. }
  7237. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7238. {
  7239. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7240. {
  7241. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7242. }
  7243. } // END OF FOR CHAdeMO_QUANTITY
  7244. }
  7245. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7246. {
  7247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7248. {
  7249. tempIndex = ((gun_index==2) ? 1: 0);
  7250. }
  7251. else
  7252. {
  7253. tempIndex = gun_index;
  7254. }
  7255. for (int index = 0; index < CCS_QUANTITY; index++)
  7256. {
  7257. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7258. {
  7259. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7260. }
  7261. } // END OF CCS_QUANTITY
  7262. }
  7263. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7264. {
  7265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7266. {
  7267. tempIndex = ((gun_index==2) ? 1: 0);
  7268. }
  7269. else
  7270. {
  7271. tempIndex = gun_index;
  7272. }
  7273. for (int index = 0; index < GB_QUANTITY; index++)
  7274. {
  7275. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7276. {
  7277. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7278. }
  7279. } // END OF GB_QUANTITY
  7280. }
  7281. else if(gunType[gun_index] == GUN_TYPE_DO)
  7282. {
  7283. tempIndex = gun_index;
  7284. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7285. {
  7286. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7287. {
  7288. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7289. }
  7290. }
  7291. }
  7292. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7293. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7294. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7295. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7296. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7297. }
  7298. // Message create ====================================================================================================
  7299. if(TRUE)
  7300. {
  7301. json_object *MeterValueReq = json_object_new_object();
  7302. json_object *MeterValues = json_object_new_array();
  7303. json_object *sampledValues = json_object_new_array();
  7304. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7305. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7306. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7307. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7308. {
  7309. json_object *MeterValue = json_object_new_object();
  7310. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7311. {
  7312. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7313. {
  7314. json_object *sampledValue = json_object_new_object();
  7315. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7316. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7317. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7318. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7319. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7320. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7321. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7322. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7323. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7324. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7325. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7326. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7327. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7328. json_object_array_add(sampledValues, sampledValue);
  7329. }
  7330. }
  7331. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7332. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7333. json_object_array_add(MeterValues, MeterValue);
  7334. }
  7335. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7336. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7337. ,gun_index + 1
  7338. ,MESSAGE_TYPE_CALL
  7339. ,guid
  7340. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7341. json_object_put(MeterValueReq);
  7342. }
  7343. // Put request guid to hash map
  7344. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7345. 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*/)
  7346. {
  7347. result = PASS;
  7348. //DEBUG_INFO("MeterValues mapitem pass\n");
  7349. }
  7350. if((dataType != ReadingContext_Trigger) &&
  7351. (dataType != ReadingContext_Sample_Clock) &&
  7352. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7353. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7354. else
  7355. {
  7356. if(FirstHeartBeat)
  7357. LWS_Send(queuedata +2);
  7358. }
  7359. return result;
  7360. }
  7361. int sendLogStatusNotificationRequest(char *status)
  7362. {
  7363. mtrace();
  7364. int result = PASS;
  7365. char message[4096]={0};
  7366. char guid[37]={0};
  7367. char tempdata[128]={0};
  7368. json_object *LogStatusNotification = json_object_new_object();
  7369. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7370. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7371. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7372. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7373. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7374. random_uuid(guid);
  7375. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7376. json_object_put(LogStatusNotification);
  7377. LWS_Send(message);
  7378. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7379. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7380. {
  7381. result = PASS;
  7382. }
  7383. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7384. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7385. return result;
  7386. }
  7387. int sendSecurityEventNotificationRequest()
  7388. {
  7389. mtrace();
  7390. int result = PASS;
  7391. char message[4096]={0};
  7392. char guid[37]={0};
  7393. char tempdata[128]={0};
  7394. json_object *SecurityEventNotification = json_object_new_object();
  7395. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7396. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7397. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7398. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7399. random_uuid(guid);
  7400. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7401. json_object_put(SecurityEventNotification);
  7402. LWS_Send(message);
  7403. sprintf(tempdata, "SecurityEventNotification,0");
  7404. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7405. {
  7406. result = PASS;
  7407. }
  7408. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7409. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7410. return result;
  7411. }
  7412. int sendSignCertificateRequest()
  7413. {
  7414. mtrace();
  7415. int result = PASS;
  7416. char message[4096]={0};
  7417. char guid[37]={0};
  7418. char tempdata[128]={0};
  7419. json_object *SignCertificate = json_object_new_object();
  7420. DEBUG_INFO("sendSignCertificateRequest...\n");
  7421. // Read csr file content
  7422. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7423. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7424. char *line = NULL;
  7425. size_t len = 0;
  7426. while(getline(&line, &len, fp) != -1)
  7427. {
  7428. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7429. {
  7430. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7431. }
  7432. }
  7433. fclose(fp);
  7434. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7435. random_uuid(guid);
  7436. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7437. json_object_put(SignCertificate);
  7438. LWS_Send(message);
  7439. sprintf(tempdata, "SignCertificate,0");
  7440. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7441. {
  7442. result = PASS;
  7443. }
  7444. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7445. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7446. return result;
  7447. }
  7448. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7449. {
  7450. mtrace();
  7451. int result = PASS;
  7452. char message[110]={0};
  7453. char guid[37]={0};
  7454. char tempdata[65]={0};
  7455. json_object *FirmwareStatusNotification = json_object_new_object();
  7456. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7457. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7458. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7459. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7460. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7461. random_uuid(guid);
  7462. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7463. json_object_put(FirmwareStatusNotification);
  7464. LWS_Send(message);
  7465. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7466. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7467. {
  7468. result = PASS;
  7469. }
  7470. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7471. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7472. return result;
  7473. }
  7474. //==========================================
  7475. // send confirm routine
  7476. //==========================================
  7477. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7478. {
  7479. mtrace();
  7480. int result = FAIL;
  7481. char message[100]={0};
  7482. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7483. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7484. LWS_Send(message);
  7485. result = TRUE;
  7486. return result;
  7487. }
  7488. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7489. {
  7490. mtrace();
  7491. int result = FAIL;
  7492. char message[100]={0};
  7493. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7494. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7495. LWS_Send(message);
  7496. result = TRUE;
  7497. return result;
  7498. }
  7499. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7500. {
  7501. mtrace();
  7502. int result = FAIL;
  7503. char message[100]={0};
  7504. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7505. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7506. LWS_Send(message);
  7507. result = TRUE;
  7508. return result;
  7509. }
  7510. int sendClearCacheConfirmation(char *uuid,char *payload)
  7511. {
  7512. mtrace();
  7513. int result = FAIL;
  7514. char message[500]={0};
  7515. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7516. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7517. LWS_Send(message);
  7518. return result;
  7519. }
  7520. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7521. {
  7522. mtrace();
  7523. int result = FAIL;
  7524. char message[500]={0};
  7525. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7526. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7527. LWS_Send(message);
  7528. return result;
  7529. }
  7530. int sendDataTransferConfirmation(char *uuid,char *payload)
  7531. {
  7532. mtrace();
  7533. char statusStr[20]={0};
  7534. char dataStr[10]={0};
  7535. char sstr[20]={0};
  7536. int c = 0;
  7537. char *loc;
  7538. int result = FAIL;
  7539. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7540. /**********************status**************************/
  7541. loc = strstr(payload, "status");
  7542. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7543. c = 0;
  7544. while (loc[3+strlen("status")+c] != '\"')
  7545. {
  7546. sstr[c] = loc[3+strlen("status")+c];
  7547. c++;
  7548. }
  7549. sstr[c] = '\0';
  7550. strcpy(statusStr, sstr);
  7551. /**********************data**************************/
  7552. loc = strstr(payload, "data");
  7553. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7554. c = 0;
  7555. while (loc[3+strlen("data")+c] != '\"')
  7556. {
  7557. sstr[c] = loc[3+strlen("data")+c];
  7558. c++;
  7559. }
  7560. sstr[c] = '\0';
  7561. strcpy(dataStr, sstr);
  7562. return result;
  7563. }
  7564. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7565. {
  7566. mtrace();
  7567. int result = FAIL;
  7568. char message[1000]={0};
  7569. int CompositeScheduleIndex = 0;
  7570. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7571. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7572. if(nPeriod == 0)
  7573. {
  7574. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7575. {
  7576. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7577. ,MESSAGE_TYPE_CALLRESULT
  7578. ,uuid
  7579. ,payload
  7580. ,connectorIdInt);
  7581. }
  7582. else
  7583. {
  7584. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7585. ,MESSAGE_TYPE_CALLRESULT
  7586. ,uuid
  7587. ,payload
  7588. ,connectorIdInt
  7589. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7590. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7591. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7592. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7593. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7594. }
  7595. }
  7596. else
  7597. {
  7598. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7599. ,MESSAGE_TYPE_CALLRESULT
  7600. ,uuid
  7601. ,payload
  7602. ,connectorIdInt
  7603. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7604. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7605. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7606. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7607. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7608. {
  7609. if (idx_sample == 0)
  7610. {
  7611. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7612. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7613. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7614. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7615. }
  7616. else
  7617. {
  7618. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7619. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7620. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7621. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7622. }
  7623. }
  7624. sprintf(message + strlen(message), "]}}]");
  7625. }
  7626. LWS_Send(message);
  7627. result = TRUE;
  7628. return result;
  7629. }
  7630. int sendGetConfigurationConfirmation(char *uuid)
  7631. {
  7632. mtrace();
  7633. int result = FAIL;
  7634. int MaxKeySupported = 0;
  7635. int sentConfigurationNumber= 0;
  7636. int sentunConfigurationNumber= 0;
  7637. char message[1024*10]={0};
  7638. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7639. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7640. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7641. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7642. ,MESSAGE_TYPE_CALLRESULT
  7643. ,uuid );
  7644. //configuration key
  7645. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7646. {
  7647. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7648. {
  7649. if (sentConfigurationNumber == 0)
  7650. {
  7651. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7652. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7653. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7654. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7655. }
  7656. else
  7657. {
  7658. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7659. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7660. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7661. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7662. }
  7663. sentConfigurationNumber = sentConfigurationNumber + 1;
  7664. }
  7665. }
  7666. sprintf(message + strlen(message), "]");
  7667. if(UnknownKeynum != 0)
  7668. {
  7669. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7670. //unkown key
  7671. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7672. {
  7673. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7674. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7675. if(sentunConfigurationNumber == 0)
  7676. {
  7677. sprintf(message + strlen(message), "\"%s\""
  7678. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7679. }
  7680. else
  7681. {
  7682. sprintf(message + strlen(message), ",\"%s\""
  7683. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7684. }
  7685. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7686. }
  7687. sprintf(message + strlen(message), "]");
  7688. }
  7689. sprintf(message + strlen(message), "}]");
  7690. LWS_Send(message);
  7691. return result;
  7692. }
  7693. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7694. {
  7695. mtrace();
  7696. int result = FAIL;
  7697. char message[400]={0};
  7698. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7699. if(strcmp(payload,"")==0)
  7700. {
  7701. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7702. }
  7703. else
  7704. {
  7705. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7706. }
  7707. LWS_Send(message);
  7708. result = TRUE;
  7709. return result;
  7710. }
  7711. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7712. {
  7713. mtrace();
  7714. int result = FAIL;
  7715. char message[80]={0};
  7716. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7717. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7718. LWS_Send(message);
  7719. result = TRUE;
  7720. return result;
  7721. }
  7722. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7723. {
  7724. mtrace();
  7725. int result = FAIL;
  7726. char message[80]={0};
  7727. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7728. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7729. LWS_Send(message);
  7730. result = TRUE;
  7731. return result;
  7732. }
  7733. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7734. {
  7735. mtrace();
  7736. int result = FAIL;
  7737. char message[80]={0};
  7738. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7739. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7740. LWS_Send(message);
  7741. result = TRUE;
  7742. return result;
  7743. }
  7744. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7745. {
  7746. mtrace();
  7747. int result = FAIL;
  7748. char message[80]={0};
  7749. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7750. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7751. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7752. LWS_Send(message);
  7753. result = TRUE;
  7754. return result;
  7755. }
  7756. int sendResetConfirmation(char *uuid,char *payload)
  7757. {
  7758. mtrace();
  7759. int result = FAIL;
  7760. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7761. char message[80]={0};
  7762. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7763. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7764. LWS_Send(message);
  7765. result = TRUE;
  7766. return result;
  7767. }
  7768. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7769. {
  7770. mtrace();
  7771. int result = FAIL;
  7772. char message[500]={0};
  7773. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7774. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7775. LWS_Send(message);
  7776. result = TRUE;
  7777. return result;
  7778. }
  7779. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7780. {
  7781. mtrace();
  7782. int result = FAIL;
  7783. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7784. char message[80]={0};
  7785. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7786. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7787. LWS_Send(message);
  7788. result = TRUE;
  7789. return result;
  7790. }
  7791. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7792. {
  7793. mtrace();
  7794. int result = FAIL;
  7795. char message[80]={0};
  7796. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7797. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7798. LWS_Send(message);
  7799. result = TRUE;
  7800. return result;
  7801. }
  7802. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7803. {
  7804. mtrace();
  7805. int result = FAIL;
  7806. char message[80]={0};
  7807. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7808. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7809. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7810. LWS_Send(message);
  7811. result = TRUE;
  7812. return result;
  7813. }
  7814. int sendUpdateFirmwareConfirmation(char *uuid)
  7815. {
  7816. mtrace();
  7817. int result = FAIL;
  7818. char message[60]={0};
  7819. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7820. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7821. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7822. LWS_Send(message);
  7823. result = TRUE;
  7824. return result;
  7825. }
  7826. int sendCertificateSignedConfirmation(char *uuid)
  7827. {
  7828. mtrace();
  7829. int result = PASS;
  7830. char message[4096]={0};
  7831. json_object *CertificateSigned = json_object_new_object();
  7832. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7833. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7834. sprintf(message,"[%d,\"%s\",%s]"
  7835. ,MESSAGE_TYPE_CALLRESULT
  7836. ,uuid
  7837. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7838. json_object_put(CertificateSigned);
  7839. LWS_Send(message);
  7840. return result;
  7841. }
  7842. int sendDeleteCertificateConfirmation(char *uuid)
  7843. {
  7844. mtrace();
  7845. int result = PASS;
  7846. char message[4096]={0};
  7847. json_object *DeleteCertificate = json_object_new_object();
  7848. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7849. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7850. sprintf(message,"[%d,\"%s\",%s]"
  7851. ,MESSAGE_TYPE_CALLRESULT
  7852. ,uuid
  7853. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7854. json_object_put(DeleteCertificate);
  7855. LWS_Send(message);
  7856. return result;
  7857. }
  7858. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7859. {
  7860. mtrace();
  7861. int result = PASS;
  7862. char message[4096]={0};
  7863. json_object *ExtendedTriggerMessage = json_object_new_object();
  7864. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7865. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7866. sprintf(message,"[%d,\"%s\",%s]"
  7867. ,MESSAGE_TYPE_CALLRESULT
  7868. ,uuid
  7869. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7870. json_object_put(ExtendedTriggerMessage);
  7871. LWS_Send(message);
  7872. return result;
  7873. }
  7874. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7875. {
  7876. mtrace();
  7877. int result = PASS;
  7878. char message[4096]={0};
  7879. json_object *GetInstalledCertificateIds = json_object_new_object();
  7880. json_object *certificateHashDataDatas = json_object_new_array();
  7881. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7882. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7883. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7884. {
  7885. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7886. {
  7887. json_object *certificateHashData = json_object_new_object();
  7888. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7889. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7890. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7891. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7892. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7893. }
  7894. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7895. }
  7896. else
  7897. {
  7898. json_object_put(certificateHashDataDatas);
  7899. }
  7900. sprintf(message,"[%d,\"%s\",%s]"
  7901. ,MESSAGE_TYPE_CALLRESULT
  7902. ,uuid
  7903. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7904. json_object_put(GetInstalledCertificateIds);
  7905. LWS_Send(message);
  7906. return result;
  7907. }
  7908. int sendGetLogConfirmation(char *uuid)
  7909. {
  7910. mtrace();
  7911. int result = PASS;
  7912. char message[4096]={0};
  7913. json_object *GetLog = json_object_new_object();
  7914. DEBUG_INFO("sendGetLogConfirmation...\n");
  7915. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7916. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7917. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7918. sprintf(message,"[%d,\"%s\",%s]"
  7919. ,MESSAGE_TYPE_CALLRESULT
  7920. ,uuid
  7921. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7922. json_object_put(GetLog);
  7923. LWS_Send(message);
  7924. return result;
  7925. }
  7926. int sendInstallCertificateConfirmation(char *uuid)
  7927. {
  7928. mtrace();
  7929. int result = PASS;
  7930. char message[4096]={0};
  7931. json_object *InstallCertificate = json_object_new_object();
  7932. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7933. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7934. sprintf(message,"[%d,\"%s\",%s]"
  7935. ,MESSAGE_TYPE_CALLRESULT
  7936. ,uuid
  7937. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7938. json_object_put(InstallCertificate);
  7939. LWS_Send(message);
  7940. return result;
  7941. }
  7942. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7943. {
  7944. mtrace();
  7945. int result = PASS;
  7946. char message[4096]={0};
  7947. json_object *SignedUpdateFirmware = json_object_new_object();
  7948. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7949. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7950. sprintf(message,"[%d,\"%s\",%s]"
  7951. ,MESSAGE_TYPE_CALLRESULT
  7952. ,uuid
  7953. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7954. json_object_put(SignedUpdateFirmware);
  7955. LWS_Send(message);
  7956. return result;
  7957. }
  7958. int sendUnknownConfirmation(char *uuid)
  7959. {
  7960. mtrace();
  7961. int result = PASS;
  7962. char message[256]={0};
  7963. DEBUG_INFO("sendUnknownConfirmation...\n");
  7964. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7965. LWS_Send(message);
  7966. return result;
  7967. }
  7968. //==========================================
  7969. // Handle server request routine Start
  7970. //==========================================
  7971. int handleCancelReservationRequest(char *uuid, char *payload)
  7972. {
  7973. mtrace();
  7974. int result = FAIL;
  7975. int gunNO = 0;
  7976. int reservationIdInt = -1;
  7977. char comfirmstr[20];
  7978. DEBUG_INFO("handleCancelReservationRequest...\n");
  7979. json_object *CancelReservation;
  7980. CancelReservation = json_tokener_parse(payload);
  7981. if(!is_error(CancelReservation))
  7982. {
  7983. // Required data
  7984. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7985. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7986. }
  7987. json_object_put(CancelReservation);
  7988. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7989. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7990. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7991. if(reservationIdInt != -1)
  7992. {
  7993. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7994. //check Transaction active
  7995. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7996. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7997. {
  7998. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7999. {
  8000. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8001. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8002. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8003. {
  8004. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8005. }
  8006. else
  8007. {
  8008. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8009. }
  8010. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8011. goto end;
  8012. }
  8013. }
  8014. for (int index = 0; index < CCS_QUANTITY; index++)
  8015. {
  8016. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8017. {
  8018. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8019. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8020. if(gunType[2] == GUN_TYPE_CCS)
  8021. {
  8022. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8023. }
  8024. else
  8025. {
  8026. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8027. }
  8028. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8029. goto end;
  8030. }
  8031. }
  8032. for (int index = 0; index < GB_QUANTITY; index++)
  8033. {
  8034. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8035. {
  8036. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8037. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8038. if(gunType[2] == GUN_TYPE_GBT)
  8039. {
  8040. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8041. }
  8042. else
  8043. {
  8044. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8045. }
  8046. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8047. goto end;
  8048. }
  8049. }
  8050. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8051. {
  8052. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8053. {
  8054. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8055. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8056. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8057. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8058. goto end;
  8059. }
  8060. }
  8061. for (int index = 0; index < AC_QUANTITY; index++)
  8062. {
  8063. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8064. {
  8065. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8066. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8067. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8068. {
  8069. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8070. }
  8071. else
  8072. {
  8073. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8074. }
  8075. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8076. goto end;
  8077. }
  8078. }
  8079. }
  8080. //The reservationId does NOT match the reservationId
  8081. sendCancelReservationConfirmation(uuid, comfirmstr);
  8082. end:
  8083. // Fill in ocpp packet uuid
  8084. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  8085. return result;
  8086. }
  8087. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8088. {
  8089. mtrace();
  8090. int result = FAIL;
  8091. int gunIndex = -1;
  8092. char typeStr[16]={0};
  8093. char comfirmstr[20];
  8094. int specificId = FALSE;
  8095. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8096. json_object *ChangeAvailability;
  8097. ChangeAvailability = json_tokener_parse(payload);
  8098. if(!is_error(ChangeAvailability))
  8099. {
  8100. // Required data
  8101. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8102. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8103. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8104. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8105. }
  8106. json_object_put(ChangeAvailability);
  8107. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8108. {
  8109. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8110. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8111. }
  8112. else if(gunIndex == 0)
  8113. {
  8114. for(int i=0; i < gunTotalNumber; i++)
  8115. {
  8116. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  8117. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  8118. }
  8119. }
  8120. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8121. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8122. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8123. {
  8124. specificId = TRUE;
  8125. }
  8126. if(specificId == FALSE)
  8127. goto end;
  8128. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8129. {
  8130. //----------------------gunIndex is 0 ------------------------------------------------//
  8131. if(gunIndex == 0)
  8132. {
  8133. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8134. {
  8135. for(int i=0; i < gunTotalNumber; i++)
  8136. {
  8137. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8138. {
  8139. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8140. {
  8141. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8142. {
  8143. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8144. goto end;
  8145. }
  8146. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8147. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8148. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8149. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8150. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8151. {
  8152. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8153. goto end;
  8154. }
  8155. }
  8156. }//END FOR CHAdeMO_QUANTITY
  8157. for (int index = 0; index < CCS_QUANTITY; index++)
  8158. {
  8159. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8160. {
  8161. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8162. {
  8163. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8164. goto end;
  8165. }
  8166. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8167. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8168. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8169. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8170. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8171. {
  8172. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8173. goto end;
  8174. }
  8175. }
  8176. }//END FOR CCS_QUANTITY
  8177. for (int index = 0; index < GB_QUANTITY; index++)
  8178. {
  8179. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8180. {
  8181. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8182. {
  8183. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8184. goto end;
  8185. }
  8186. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8187. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8188. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8189. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8190. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8191. {
  8192. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8193. goto end;
  8194. }
  8195. }
  8196. }// END FOR GB_QUANTITY
  8197. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8198. {
  8199. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8200. {
  8201. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8202. {
  8203. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8204. goto end;
  8205. }
  8206. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8207. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8208. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8209. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8210. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8211. {
  8212. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8213. goto end;
  8214. }
  8215. }
  8216. }// END FOR GENERAL_GUN_QUANTITY
  8217. for (int index = 0; index < AC_QUANTITY; index++)
  8218. {
  8219. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8220. {
  8221. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8222. {
  8223. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8224. goto end;
  8225. }
  8226. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8227. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8228. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8229. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8230. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8231. {
  8232. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8233. goto end;
  8234. }
  8235. }
  8236. }//END FOR AC_QUANTITY
  8237. }// END FOR gunTotalNumber
  8238. }
  8239. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8240. {
  8241. for(int i=0; i < gunTotalNumber; i++)
  8242. {
  8243. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8244. {
  8245. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8246. goto end;
  8247. }
  8248. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8249. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8250. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8251. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8252. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8253. {
  8254. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8255. goto end;
  8256. }
  8257. }
  8258. }
  8259. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8260. goto end;
  8261. }
  8262. //----------------------gunIndex is not 0 ------------------------------------------------//
  8263. //check Transaction active
  8264. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8265. {
  8266. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8267. {
  8268. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8269. {
  8270. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8271. goto end;
  8272. }
  8273. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8274. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8275. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8276. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8277. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8278. {
  8279. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8280. goto end;
  8281. }
  8282. else
  8283. {
  8284. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8285. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8286. goto end;
  8287. }
  8288. }
  8289. }//END FOR CHAdeMO_QUANTITY
  8290. for (int index = 0; index < CCS_QUANTITY; index++)
  8291. {
  8292. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8293. {
  8294. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8295. {
  8296. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8297. goto end;
  8298. }
  8299. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8300. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8301. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8302. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8303. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8304. {
  8305. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8306. goto end;
  8307. }
  8308. else
  8309. {
  8310. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8311. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8312. goto end;
  8313. }
  8314. }
  8315. }//END FOR CCS_QUANTITY
  8316. for (int index = 0; index < GB_QUANTITY; index++)
  8317. {
  8318. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8319. {
  8320. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8321. {
  8322. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8323. goto end;
  8324. }
  8325. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8326. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8327. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8328. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8329. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8330. {
  8331. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8332. goto end;
  8333. }
  8334. else
  8335. {
  8336. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8337. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8338. goto end;
  8339. }
  8340. }
  8341. }// END FOR GB_QUANTITY
  8342. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8343. {
  8344. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8345. {
  8346. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8347. {
  8348. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8349. goto end;
  8350. }
  8351. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8352. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8353. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8354. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8355. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8356. {
  8357. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8358. goto end;
  8359. }
  8360. else
  8361. {
  8362. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8363. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8364. goto end;
  8365. }
  8366. }
  8367. }// END FOR GENERAL_GUN_QUANTITY
  8368. for (int index = 0; index < AC_QUANTITY; index++)
  8369. {
  8370. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8371. {
  8372. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8373. {
  8374. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8375. goto end;
  8376. }
  8377. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8378. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8379. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8380. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8381. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8382. {
  8383. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8384. goto end;
  8385. }
  8386. else
  8387. {
  8388. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8389. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8390. goto end;
  8391. }
  8392. }
  8393. }//END FOR AC_QUANTITY
  8394. }//END FOR AvailabilityTypeStr[Inoperative]
  8395. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8396. {
  8397. //----------------------gunIndex is 0 ------------------------------------------------//
  8398. if(gunIndex == 0)
  8399. {
  8400. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8401. {
  8402. for(int i=0; i < gunTotalNumber; i++)
  8403. {
  8404. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8405. {
  8406. 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
  8407. {
  8408. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8409. goto end;
  8410. }
  8411. }//END FOR CHAdeMO_QUANTITY
  8412. for (int index = 0; index < CCS_QUANTITY; index++)
  8413. {
  8414. 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
  8415. {
  8416. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8417. goto end;
  8418. }
  8419. }//END FOR CCS_QUANTITY
  8420. for (int index = 0; index < GB_QUANTITY; index++)
  8421. {
  8422. 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
  8423. {
  8424. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8425. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8426. goto end;
  8427. }
  8428. }// END FOR GB_QUANTITY
  8429. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8430. {
  8431. 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
  8432. {
  8433. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8435. goto end;
  8436. }
  8437. }// END FOR GENERAL_GUN_QUANTITY
  8438. for (int index = 0; index < AC_QUANTITY; index++)
  8439. {
  8440. 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
  8441. {
  8442. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8443. goto end;
  8444. }
  8445. }//END FOR CHAdeMO_QUANTITY
  8446. }// END FOR gunTotalNumber
  8447. }
  8448. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8449. {
  8450. for(int i=0; i < gunTotalNumber; i++)
  8451. {
  8452. for (int index = 0; index < AC_QUANTITY; index++)
  8453. {
  8454. 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
  8455. {
  8456. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8457. goto end;
  8458. }
  8459. }//END FOR CHAdeMO_QUANTITY
  8460. } // END FOR gunTotalNumber
  8461. }
  8462. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8463. goto end;
  8464. }
  8465. //----------------------gunIndex is not 0 ------------------------------------------------//
  8466. //check Transaction active
  8467. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8468. {
  8469. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8470. {
  8471. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8472. goto end;
  8473. }
  8474. }//END FOR CHAdeMO_QUANTITY
  8475. for (int index = 0; index < CCS_QUANTITY; index++)
  8476. {
  8477. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8478. {
  8479. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8480. goto end;
  8481. }
  8482. }//END FOR CCS_QUANTITY
  8483. for (int index = 0; index < GB_QUANTITY; index++)
  8484. {
  8485. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8486. {
  8487. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8488. goto end;
  8489. }
  8490. }// END FOR GB_QUANTITY
  8491. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8492. {
  8493. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8494. {
  8495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8496. goto end;
  8497. }
  8498. }// END FOR GENERAL_GUN_QUANTITY
  8499. for (int index = 0; index < AC_QUANTITY; index++)
  8500. {
  8501. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8502. {
  8503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8504. goto end;
  8505. }
  8506. }//END FOR AC_QUANTITY
  8507. }//END FOR AvailabilityTypeStr[Operative]
  8508. end:
  8509. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8510. {
  8511. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8512. }
  8513. else
  8514. {
  8515. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8516. }
  8517. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8518. {
  8519. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8520. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8521. }
  8522. else if(gunIndex == 0)
  8523. {
  8524. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8525. {
  8526. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8527. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8528. }
  8529. }
  8530. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8531. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8532. return result;
  8533. }
  8534. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8535. {
  8536. mtrace();
  8537. int valueInvalid = NO;
  8538. int result = FAIL;
  8539. char keystr[40]={0};
  8540. char valuestr[501]={0}; //value should be limited in 500 bytes
  8541. char comfirmstr[20]={0};
  8542. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8543. json_object *ChangeConfiguration;
  8544. ChangeConfiguration = json_tokener_parse(payload);
  8545. if(!is_error(ChangeConfiguration))
  8546. {
  8547. // Required data
  8548. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8549. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8550. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8551. {
  8552. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8553. }
  8554. else
  8555. {
  8556. valueInvalid = YES;
  8557. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8558. }
  8559. }
  8560. json_object_put(ChangeConfiguration);
  8561. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8562. {
  8563. DEBUG_ERROR("Payload is null or not accepted.\n");
  8564. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8565. }
  8566. else
  8567. {
  8568. int status = setKeyValue(keystr, valuestr);
  8569. switch(status)
  8570. {
  8571. case ConfigurationStatus_Accepted:
  8572. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8573. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8574. StoreConfigurationTable();
  8575. break;
  8576. case RebootRequired:
  8577. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8578. StoreConfigurationTable();
  8579. break;
  8580. case NotSupported:
  8581. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8582. break;
  8583. case ConfigurationStatus_Rejected:
  8584. default:
  8585. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8586. break;
  8587. }
  8588. }
  8589. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8590. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8591. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8592. {
  8593. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8594. SetOcppConnStatus(FALSE);
  8595. }
  8596. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8597. {
  8598. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8599. }
  8600. return result;
  8601. }
  8602. int handleClearCacheRequest(char *uuid, char *payload)
  8603. {
  8604. mtrace();
  8605. int result = FAIL;
  8606. char comfirmstr[20];
  8607. char rmFileCmd[100]={0};
  8608. struct stat stats;
  8609. DEBUG_INFO("handleClearCacheRequest...\n");
  8610. stat("/Storage/OCPP_PH", &stats);
  8611. // Check for directory existence
  8612. if (S_ISDIR(stats.st_mode) == 1)
  8613. {}
  8614. else
  8615. {
  8616. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8617. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8618. system(rmFileCmd);
  8619. }
  8620. if(OCPP_cleanLocalCache())
  8621. {
  8622. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8623. }
  8624. else
  8625. {
  8626. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8627. }
  8628. sendClearCacheConfirmation(uuid, comfirmstr);
  8629. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8630. return result;
  8631. }
  8632. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8633. {
  8634. mtrace();
  8635. int result = FAIL;
  8636. int resultRename;
  8637. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8638. char chargingProfilePurposeStr[26]={0};
  8639. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8640. char tempchargingProfilePurposeStr[26]={0};
  8641. char str[100]={0};
  8642. char fname[200]={0};
  8643. char comfirmstr[20]={0};
  8644. char word[1600]={0};
  8645. int clearflag = FALSE;
  8646. int chargingProfileIdIsNULL = FALSE;
  8647. int connectorIsNULL = FALSE;
  8648. int chargingProfilePurposeIsNULL = FALSE;
  8649. int stackLevelIsNULL = FALSE;
  8650. //int GotoEnd = FALSE;
  8651. FILE *fptr1, *fptr2;
  8652. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8653. int n_chargingProfile=0;
  8654. int isEmptyFile = FALSE;
  8655. char sLineWord[1600]={0};
  8656. char chargingProfiles[10][100]={0};
  8657. int ChargeProfileCount = 0;
  8658. int ch;
  8659. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8660. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8661. json_object *ClearChargingProfile;
  8662. ClearChargingProfile = json_tokener_parse(payload);
  8663. if(!is_error(ClearChargingProfile))
  8664. {
  8665. // Optional data
  8666. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8667. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8668. else
  8669. chargingProfileIdIsNULL = TRUE;
  8670. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8671. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8672. else
  8673. connectorIsNULL = TRUE;
  8674. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8675. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8676. else
  8677. chargingProfilePurposeIsNULL = TRUE;
  8678. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8679. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8680. else
  8681. stackLevelIsNULL = TRUE;
  8682. }
  8683. json_object_put(ClearChargingProfile);
  8684. if(connectorIsNULL == FALSE)
  8685. {
  8686. switch(connectorIdInt)
  8687. {
  8688. case 0:
  8689. if(chargingProfilePurposeIsNULL == TRUE)
  8690. {
  8691. int l = 0;
  8692. strcpy(fname, ChargePointMaxProfile_JSON);
  8693. if((access(fname,F_OK))!=-1)
  8694. {
  8695. strcpy(chargingProfiles[l], fname);
  8696. l = l + 1;
  8697. }
  8698. strcpy(fname, TxDefaultProfile_0_JSON);
  8699. if((access(fname,F_OK))!=-1)
  8700. {
  8701. strcpy(chargingProfiles[l], fname);
  8702. l = l + 1;
  8703. }
  8704. ChargeProfileCount = l;
  8705. }
  8706. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8707. {
  8708. strcpy(fname, ChargePointMaxProfile_JSON);
  8709. if((access(fname,F_OK))!=-1)
  8710. {
  8711. strcpy(chargingProfiles[0], fname);
  8712. ChargeProfileCount = 1;
  8713. }
  8714. }
  8715. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8716. {
  8717. strcpy(fname, TxDefaultProfile_0_JSON);
  8718. if((access(fname,F_OK))!=-1)
  8719. {
  8720. strcpy(chargingProfiles[0], fname);
  8721. ChargeProfileCount = 1;
  8722. }
  8723. }
  8724. break;
  8725. default:
  8726. if(chargingProfilePurposeIsNULL == TRUE)
  8727. {
  8728. int m = 0;
  8729. memset(fname, 0, ARRAY_SIZE(fname));
  8730. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8731. if((access(fname,F_OK))!=-1)
  8732. {
  8733. strcpy(chargingProfiles[m], fname);
  8734. m = m + 1;
  8735. }
  8736. memset(fname, 0, ARRAY_SIZE(fname));
  8737. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8738. if((access(fname,F_OK))!=-1)
  8739. {
  8740. strcpy(chargingProfiles[m], fname);
  8741. m = m + 1;
  8742. }
  8743. ChargeProfileCount = m;
  8744. }
  8745. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8746. {
  8747. //strcpy(fname, TxDefaultProfile_1_JSON);
  8748. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8749. if((access(fname,F_OK))!=-1)
  8750. {
  8751. strcpy(chargingProfiles[0], fname);
  8752. ChargeProfileCount = 1;
  8753. }
  8754. }
  8755. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8756. {
  8757. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8758. if((access(fname,F_OK))!=-1)
  8759. {
  8760. strcpy(chargingProfiles[0], fname);
  8761. ChargeProfileCount = 1;
  8762. }
  8763. //strcpy(fname, TxProfile_1_JSON);
  8764. }
  8765. //strcpy(fname, ChargePointMaxProfile_JSON );
  8766. break;
  8767. }
  8768. }
  8769. else // Check all Charging Profiles
  8770. {
  8771. int i = 0;
  8772. char fnametemp[200]={0};
  8773. ChargeProfileCount = 0;
  8774. //Check ChargePointMaxProfile.json exit
  8775. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8776. {
  8777. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8778. i = i + 1;
  8779. }
  8780. //Check TxDefaultProfile_0.json exit
  8781. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8782. {
  8783. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8784. i = i + 1;
  8785. }
  8786. //Check TxDefaultProfile_%d.json
  8787. for(int j=1; j <= gunTotalNumber; j++)
  8788. {
  8789. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8790. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8791. if((access(fnametemp,F_OK))!=-1)
  8792. {
  8793. strcpy(chargingProfiles[i], fnametemp);
  8794. i = i + 1;
  8795. }
  8796. }
  8797. //Check TxProfile_%d.json
  8798. for(int j=1; j <= gunTotalNumber; j++)
  8799. {
  8800. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8801. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8802. if((access(fnametemp,F_OK))!=-1)
  8803. {
  8804. strcpy(chargingProfiles[i], fnametemp);
  8805. i = i + 1;
  8806. }
  8807. }
  8808. ChargeProfileCount = i;
  8809. }// End connectorIsNULL is TRUE
  8810. if(ChargeProfileCount == 0)
  8811. {
  8812. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8813. goto end;
  8814. }
  8815. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8816. {
  8817. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8818. goto end;
  8819. }
  8820. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8821. {
  8822. memset(str, 0, ARRAY_SIZE(str));
  8823. // clear temp file
  8824. sprintf(str,"rm -f %s",temp);
  8825. system(str);
  8826. for(int k=0; k < ChargeProfileCount; k++)
  8827. {
  8828. memset(str, 0, ARRAY_SIZE(str));
  8829. //clear file in C
  8830. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8831. system(str);
  8832. }
  8833. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8834. goto end;
  8835. }
  8836. else if(connectorIsNULL == TRUE)
  8837. {
  8838. for(int k=0; k < ChargeProfileCount; k++)
  8839. {
  8840. fptr1 = fopen(chargingProfiles[k], "r");
  8841. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8842. //Check Charging Profile Count
  8843. while(fscanf(fptr1, "%s", word) != EOF)
  8844. {
  8845. //DEBUG_INFO("word=%s\n",word);
  8846. if(strstr(word, "chargingProfileId")!= NULL)
  8847. {
  8848. //DEBUG_INFO("test chargingProfileId \n");
  8849. n_chargingProfile = n_chargingProfile + 1;
  8850. //DEBUG_INFO("chargingProfileId Found\n");
  8851. }
  8852. }
  8853. rewind(fptr1);
  8854. //search Charging Profile Element
  8855. //int i= 0;
  8856. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8857. {
  8858. json_object *tmpProfilee;
  8859. tmpProfilee = json_tokener_parse(sLineWord);
  8860. if(!is_error(tmpProfilee))
  8861. {
  8862. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8863. {
  8864. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8865. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8866. }
  8867. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8868. {
  8869. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8870. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8871. }
  8872. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8873. {
  8874. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8875. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8876. }
  8877. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8878. {
  8879. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8880. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8881. }
  8882. }
  8883. json_object_put(tmpProfilee);
  8884. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8885. {
  8886. //------- not write to fptr2-------//
  8887. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8888. //clearflag = TRUE;
  8889. }
  8890. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8891. {
  8892. //------- not write to fptr2-------//
  8893. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8894. }
  8895. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8896. {
  8897. //------- not write to fptr2-------//
  8898. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8899. }
  8900. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8901. {
  8902. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8903. }
  8904. else
  8905. {
  8906. fprintf(fptr2, sLineWord);//writing data into file
  8907. }
  8908. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8909. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8910. if(clearflag == TRUE)
  8911. {
  8912. fclose(fptr1);
  8913. fclose(fptr2);
  8914. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8915. system(str);
  8916. // clear temp file
  8917. sprintf(str,"rm -f %s",temp);
  8918. system(str);
  8919. }
  8920. else
  8921. {
  8922. fclose(fptr1);
  8923. fclose(fptr2);
  8924. memset(str, 0, ARRAY_SIZE(str));
  8925. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8926. system(str);
  8927. resultRename = rename(temp, chargingProfiles[k]);
  8928. if(resultRename == 0)
  8929. {
  8930. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8931. }
  8932. else
  8933. {
  8934. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8935. }
  8936. if(comfirmstr[0]== 0)
  8937. {
  8938. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8939. }
  8940. //Check chargingProfile is empty file
  8941. /*------ Read the file ----------------*/
  8942. fptr1=fopen(chargingProfiles[k],"r");
  8943. ch=fgetc(fptr1);
  8944. rewind(fptr1);
  8945. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8946. if(ch!=EOF)
  8947. {
  8948. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8949. {
  8950. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8951. if(sLineWord[0]=='\0')
  8952. {
  8953. isEmptyFile = TRUE;
  8954. break;
  8955. }
  8956. else
  8957. {
  8958. isEmptyFile = FALSE;
  8959. break;
  8960. }
  8961. }
  8962. }
  8963. else
  8964. isEmptyFile = TRUE;
  8965. fclose(fptr1);
  8966. if(isEmptyFile == TRUE)
  8967. {
  8968. memset(str, 0, ARRAY_SIZE(str));
  8969. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8970. system(str);
  8971. }
  8972. }
  8973. }// End of while(int k=0; k < ChargePointCount; k++)
  8974. }
  8975. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8976. {
  8977. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8978. for(int k=0; k < ChargeProfileCount; k++)
  8979. {
  8980. fptr1 = fopen(chargingProfiles[k], "r");
  8981. fptr2 = fopen(temp, "w+");
  8982. //Check Charging Profile Count
  8983. while(fscanf(fptr1, "%s", word) != EOF)
  8984. {
  8985. //DEBUG_INFO("word=%s\n",word);
  8986. if(strstr(word, "chargingProfileId")!= NULL)
  8987. {
  8988. n_chargingProfile = n_chargingProfile + 1;
  8989. }
  8990. }
  8991. rewind(fptr1);
  8992. //search Charging Profile Element
  8993. //int i= 0;
  8994. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8995. {
  8996. json_object *tmpProfilee;
  8997. tmpProfilee = json_tokener_parse(sLineWord);
  8998. if(!is_error(tmpProfilee))
  8999. {
  9000. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9001. {
  9002. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9003. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9004. }
  9005. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9006. {
  9007. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9008. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9009. }
  9010. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9011. {
  9012. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9013. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9014. }
  9015. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9016. {
  9017. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9018. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9019. }
  9020. }
  9021. json_object_put(tmpProfilee);
  9022. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9023. {
  9024. //------- not write to fptr2-------//
  9025. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9026. //clearflag = TRUE;
  9027. }
  9028. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9029. {
  9030. //------- not write to fptr2-------//
  9031. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9032. }
  9033. else if(stackLevelIsNULL == TRUE)
  9034. {
  9035. //Clear Whole File
  9036. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9037. clearflag = TRUE;
  9038. break;
  9039. }
  9040. else
  9041. {
  9042. fprintf(fptr2, sLineWord);//writing data into file
  9043. }
  9044. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9045. }
  9046. if(clearflag == TRUE)
  9047. {
  9048. fclose(fptr1);
  9049. fclose(fptr2);
  9050. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9051. system(str);
  9052. // clear temp file
  9053. sprintf(str,"rm -f %s",temp);
  9054. system(str);
  9055. }
  9056. else
  9057. {
  9058. fclose(fptr1);
  9059. fclose(fptr2);
  9060. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9061. system(str);
  9062. resultRename = rename(temp, chargingProfiles[k]);
  9063. if(resultRename == 0)
  9064. {
  9065. DEBUG_INFO("File ChargingProfile renamed successfully");
  9066. }
  9067. else
  9068. {
  9069. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9070. }
  9071. if(comfirmstr[0]== 0)
  9072. {
  9073. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9074. }
  9075. //Check chargingProfile is empty file
  9076. /*------ Read the file ----------------*/
  9077. fptr1=fopen(chargingProfiles[k],"r");
  9078. ch=fgetc(fptr1);
  9079. rewind(fptr1);
  9080. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9081. if(ch!=EOF)
  9082. {
  9083. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9084. {
  9085. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9086. if(sLineWord[0]=='\0')
  9087. {
  9088. isEmptyFile = TRUE;
  9089. break;
  9090. }
  9091. else
  9092. {
  9093. isEmptyFile = FALSE;
  9094. break;
  9095. }
  9096. }
  9097. }
  9098. else
  9099. isEmptyFile = TRUE;
  9100. fclose(fptr1);
  9101. if(isEmptyFile == TRUE)
  9102. {
  9103. memset(str, 0, ARRAY_SIZE(str));
  9104. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9105. system(str);
  9106. }
  9107. /*------- End of reading ---------------*/
  9108. }
  9109. } // while(int k=0; k < ChargeProfileCount; k++)
  9110. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9111. end:
  9112. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9113. {
  9114. if(connectorIdInt == 0)
  9115. {
  9116. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9117. {
  9118. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  9119. }
  9120. }
  9121. else
  9122. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  9123. }
  9124. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9125. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9126. return result;
  9127. }
  9128. void createFirmwareVersionByDataTransfer(void)
  9129. {
  9130. json_object *FirmwareDataTransfer = json_object_new_object();
  9131. // AC & DC model
  9132. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9133. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9134. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9135. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9136. // DC model
  9137. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9138. {
  9139. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9140. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9141. (gunType[3] != GUN_TYPE_UNKNOWN))
  9142. {
  9143. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9144. }
  9145. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9146. {
  9147. // DS DM DW
  9148. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9149. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9150. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9151. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9152. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9153. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9154. }
  9155. else
  9156. {
  9157. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9158. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9159. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9160. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9161. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9162. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9163. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9164. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9165. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9166. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9167. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9168. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9169. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9170. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9171. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9172. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9173. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9174. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9175. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9176. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9177. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9178. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9179. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9180. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9181. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9182. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9183. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9184. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9185. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9186. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9187. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9188. }
  9189. }
  9190. // 4G model
  9191. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9192. {
  9193. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9194. }
  9195. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9196. json_object_put(FirmwareDataTransfer);
  9197. }
  9198. int handleDataTransferRequest(char *uuid, char *payload)
  9199. {
  9200. mtrace();
  9201. json_object *response = json_object_new_object();
  9202. int result = FAIL;
  9203. char tempvendorId[255]={0};
  9204. char tempmessageId[50]={0};
  9205. char tempdata[1024]={0};
  9206. char message[2048]={0};
  9207. DEBUG_INFO("handleDataTransferRequest...\n");
  9208. if((uuid != NULL) && (payload != NULL))
  9209. {
  9210. json_object *DataTransfer;
  9211. DataTransfer = json_tokener_parse(payload);
  9212. if(!is_error(DataTransfer))
  9213. {
  9214. // Required data
  9215. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9216. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9217. // Optional data
  9218. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9219. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9220. if(json_object_object_get(DataTransfer, "data") != NULL)
  9221. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9222. result = PASS;
  9223. }
  9224. json_object_put(DataTransfer);
  9225. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9226. {
  9227. // Send all moudle firmware version on EVSE
  9228. createFirmwareVersionByDataTransfer();
  9229. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9230. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9231. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9232. json_object_put(response);
  9233. }
  9234. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9235. {
  9236. system("/usr/bin/run_tmate_restart.sh &");
  9237. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9238. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9239. json_object_put(response);
  9240. }
  9241. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9242. {
  9243. json_object *data;
  9244. data = json_tokener_parse(tempdata);
  9245. if(!is_error(data))
  9246. {
  9247. 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))
  9248. {
  9249. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9250. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9251. if(json_object_object_get(data, "SOC") != NULL)
  9252. {
  9253. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9254. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9255. }
  9256. if(json_object_object_get(data, "Energy") != NULL)
  9257. {
  9258. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9259. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9260. }
  9261. if(json_object_object_get(data, "Duration") != NULL)
  9262. {
  9263. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9264. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9265. }
  9266. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9267. }
  9268. else
  9269. {
  9270. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9271. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9272. }
  9273. }
  9274. else
  9275. {
  9276. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9277. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9278. }
  9279. json_object_put(data);
  9280. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9281. json_object_put(response);
  9282. }
  9283. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9284. {
  9285. json_object *data;
  9286. data = json_tokener_parse(tempdata);
  9287. if(!is_error(data))
  9288. {
  9289. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9290. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9291. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9292. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9293. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9294. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9295. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9296. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9297. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9298. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9299. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9300. }
  9301. else
  9302. {
  9303. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9304. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9305. }
  9306. json_object_put(data);
  9307. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9308. json_object_put(response);
  9309. }
  9310. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9311. {
  9312. json_object *data;
  9313. data = json_tokener_parse(tempdata);
  9314. if(!is_error(data))
  9315. {
  9316. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9317. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9318. if(json_object_object_get(data, "idToken") != NULL)
  9319. {
  9320. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9321. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9322. }
  9323. else
  9324. {
  9325. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9326. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9327. }
  9328. if(json_object_object_get(data, "price") != NULL) //v1.0
  9329. {
  9330. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9331. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9332. }
  9333. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9334. {
  9335. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9336. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9337. }
  9338. else
  9339. {
  9340. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9341. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9342. }
  9343. }
  9344. else
  9345. {
  9346. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9347. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9348. }
  9349. json_object_put(data);
  9350. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9351. json_object_put(response);
  9352. }
  9353. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9354. {
  9355. json_object *data;
  9356. data = json_tokener_parse(tempdata);
  9357. if(!is_error(data))
  9358. {
  9359. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9360. if(json_object_object_get(data, "txId") != NULL)
  9361. {
  9362. // California pricing V1.0
  9363. DEBUG_INFO("California pricing V1.0\n");
  9364. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9365. sprintf((char*)dmsVersion, "1.0");
  9366. for(int idx = 0;idx<gunTotalNumber;idx++)
  9367. {
  9368. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9369. {
  9370. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9371. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9372. if(json_object_object_get(data, "description") != NULL)
  9373. {
  9374. // California pricing V1.0
  9375. DEBUG_INFO("California pricing V1.0\n");
  9376. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9377. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9378. }
  9379. }
  9380. }
  9381. }
  9382. else if(json_object_object_get(data, "transactionId") != NULL)
  9383. {
  9384. // California pricing V2.0
  9385. DEBUG_INFO("California pricing V2.0\n");
  9386. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9387. sprintf((char*)dmsVersion, "2.0");
  9388. for(int idx=0;idx<gunTotalNumber;idx++)
  9389. {
  9390. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9391. {
  9392. if(json_object_object_get(data, "timestamp") != NULL)
  9393. {
  9394. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9395. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9396. }
  9397. else
  9398. {
  9399. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9400. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9401. }
  9402. if(json_object_object_get(data, "meterValue") != NULL)
  9403. {
  9404. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9405. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9406. }
  9407. else
  9408. {
  9409. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9410. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9411. }
  9412. if(json_object_object_get(data, "cost") != NULL)
  9413. {
  9414. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9415. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9416. }
  9417. else
  9418. {
  9419. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9420. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9421. }
  9422. if(json_object_object_get(data, "state") != NULL)
  9423. {
  9424. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9425. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9426. }
  9427. else
  9428. {
  9429. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9430. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9431. }
  9432. if(json_object_object_get(data, "chargingPrice") != NULL)
  9433. {
  9434. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9435. {
  9436. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9437. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9438. }
  9439. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9440. {
  9441. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9442. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9443. }
  9444. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9445. {
  9446. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9447. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9448. }
  9449. }
  9450. else
  9451. {
  9452. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9453. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9454. }
  9455. if(json_object_object_get(data, "idlePrice") != NULL)
  9456. {
  9457. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9458. {
  9459. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9460. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9461. }
  9462. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9463. {
  9464. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9465. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9466. }
  9467. }
  9468. if(json_object_object_get(data, "nextPeriod") != NULL)
  9469. {
  9470. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9471. {
  9472. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9473. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9474. }
  9475. else
  9476. {
  9477. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9478. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9479. }
  9480. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9481. {
  9482. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9483. {
  9484. 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")));
  9485. 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"));
  9486. }
  9487. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9488. {
  9489. 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")));
  9490. 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"));
  9491. }
  9492. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9493. {
  9494. 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")));
  9495. 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"));
  9496. }
  9497. }
  9498. else
  9499. {
  9500. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9501. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9502. }
  9503. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9504. {
  9505. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9506. {
  9507. 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")));
  9508. 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"));
  9509. }
  9510. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9511. {
  9512. 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")));
  9513. 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"));
  9514. }
  9515. }
  9516. }
  9517. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9518. {
  9519. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9520. {
  9521. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9522. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9523. }
  9524. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9525. {
  9526. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9527. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9528. }
  9529. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9530. {
  9531. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9532. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9533. }
  9534. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  9535. {
  9536. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9537. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9538. }
  9539. }
  9540. }
  9541. }
  9542. }
  9543. else
  9544. {
  9545. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9546. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9547. }
  9548. }
  9549. else
  9550. {
  9551. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9552. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9553. }
  9554. json_object_put(data);
  9555. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9556. json_object_put(response);
  9557. }
  9558. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9559. {
  9560. json_object *data;
  9561. data = json_tokener_parse(tempdata);
  9562. if(!is_error(data))
  9563. {
  9564. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9565. if(json_object_object_get(data, "txId") != NULL)
  9566. {
  9567. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9568. for(int idx = 0;idx<gunTotalNumber;idx++)
  9569. {
  9570. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9571. {
  9572. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9573. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9574. if(json_object_object_get(data, "description") != NULL)
  9575. {
  9576. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9577. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9578. }
  9579. else
  9580. {
  9581. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9582. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9583. }
  9584. }
  9585. }
  9586. }
  9587. else if(json_object_object_get(data, "transactionId") != NULL)
  9588. {
  9589. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9590. for(int idx = 0;idx<gunTotalNumber;idx++)
  9591. {
  9592. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9593. {
  9594. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9595. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9596. if(json_object_object_get(data, "cost") != NULL)
  9597. {
  9598. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  9599. ShmOCPP16DataPH->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9600. }
  9601. else
  9602. {
  9603. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9604. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9605. }
  9606. if(json_object_object_get(data, "priceText") != NULL)
  9607. {
  9608. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9609. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9610. }
  9611. else
  9612. {
  9613. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9614. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  9615. }
  9616. if(json_object_object_get(data, "qrCodeText") != NULL)
  9617. {
  9618. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9619. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9620. }
  9621. }
  9622. }
  9623. }
  9624. else
  9625. {
  9626. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9627. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9628. }
  9629. }
  9630. else
  9631. {
  9632. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9633. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9634. }
  9635. json_object_put(data);
  9636. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9637. json_object_put(response);
  9638. }
  9639. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9640. {
  9641. json_object *data;
  9642. data = json_tokener_parse(tempdata);
  9643. if(!is_error(data))
  9644. {
  9645. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9646. if(json_object_object_get(data, "Content_Type") != NULL)
  9647. {
  9648. 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))
  9649. {
  9650. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9651. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9652. {
  9653. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9654. }
  9655. }
  9656. else
  9657. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9658. }
  9659. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9660. }
  9661. else
  9662. {
  9663. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9664. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9665. }
  9666. json_object_put(data);
  9667. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9668. json_object_put(response);
  9669. }
  9670. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9671. {
  9672. json_object *data;
  9673. data = json_tokener_parse(tempdata);
  9674. if(!is_error(data))
  9675. {
  9676. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9677. if(json_object_object_get(data, "ConnectorId") != NULL)
  9678. {
  9679. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9680. }
  9681. if(json_object_object_get(data, "SerialNo") != NULL)
  9682. {
  9683. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9684. }
  9685. if(json_object_object_get(data, "Page_Index") != NULL)
  9686. {
  9687. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9688. }
  9689. if(json_object_object_get(data, "Duration") != NULL)
  9690. {
  9691. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9692. }
  9693. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9694. }
  9695. else
  9696. {
  9697. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9698. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9699. }
  9700. json_object_put(data);
  9701. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9702. json_object_put(response);
  9703. }
  9704. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9705. {
  9706. json_object *data;
  9707. data = json_tokener_parse(tempdata);
  9708. if(!is_error(data))
  9709. {
  9710. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9711. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9712. {
  9713. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9714. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9715. else
  9716. {
  9717. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9718. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9719. }
  9720. }
  9721. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9722. {
  9723. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9724. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9725. else
  9726. {
  9727. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9728. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9729. }
  9730. }
  9731. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9732. {
  9733. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9734. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9735. else
  9736. {
  9737. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9738. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9739. }
  9740. }
  9741. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9742. {
  9743. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9744. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9745. else
  9746. {
  9747. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9748. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9749. }
  9750. }
  9751. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9752. {
  9753. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9754. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9755. else
  9756. {
  9757. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9758. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9759. }
  9760. }
  9761. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9762. {
  9763. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9764. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9765. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9766. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9767. else
  9768. {
  9769. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9770. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9771. }
  9772. }
  9773. if(json_object_object_get(data, "isAuthentication") != NULL)
  9774. {
  9775. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9776. {
  9777. case 0:
  9778. case 1:
  9779. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9780. break;
  9781. default:
  9782. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9783. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9784. break;
  9785. }
  9786. }
  9787. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9788. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9789. }
  9790. else
  9791. {
  9792. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9793. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9794. }
  9795. json_object_put(data);
  9796. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9797. json_object_put(response);
  9798. }
  9799. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9800. {
  9801. json_object *data;
  9802. data = json_tokener_parse(tempdata);
  9803. if(!is_error(data))
  9804. {
  9805. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9806. if(json_object_object_get(data, "stationName") != NULL)
  9807. {
  9808. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9809. }
  9810. else
  9811. {
  9812. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9813. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9814. }
  9815. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9816. {
  9817. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9818. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9819. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9820. }
  9821. }
  9822. else
  9823. {
  9824. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9825. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9826. }
  9827. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9828. json_object_put(response);
  9829. }
  9830. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9831. {
  9832. json_object *data;
  9833. data = json_tokener_parse(tempdata);
  9834. if(!is_error(data))
  9835. {
  9836. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9837. if(json_object_object_get(data, "weatherId") != NULL)
  9838. {
  9839. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9840. }
  9841. else
  9842. {
  9843. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9844. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9845. }
  9846. if(json_object_object_get(data, "Temperature") != NULL)
  9847. {
  9848. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9849. }
  9850. else
  9851. {
  9852. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9853. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9854. }
  9855. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9856. {
  9857. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9858. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9859. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9860. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9861. }
  9862. }
  9863. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9864. {
  9865. json_object *data;
  9866. data = json_tokener_parse(tempdata);
  9867. if(!is_error(data))
  9868. {
  9869. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9870. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9871. {
  9872. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9873. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9874. }
  9875. else
  9876. {
  9877. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9878. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9879. }
  9880. }
  9881. else
  9882. {
  9883. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9884. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9885. }
  9886. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9887. json_object_put(response);
  9888. }
  9889. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9890. {
  9891. json_object *data;
  9892. data = json_tokener_parse(tempdata);
  9893. if(!is_error(data))
  9894. {
  9895. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9896. {
  9897. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9898. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9899. if(gun_index < gunTotalNumber)
  9900. {
  9901. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9902. {
  9903. json_object *responsedata = json_object_new_object();
  9904. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9905. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9906. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9907. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9908. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9909. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9910. }
  9911. else
  9912. {
  9913. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9914. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9915. }
  9916. }
  9917. else
  9918. {
  9919. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9920. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9921. }
  9922. }
  9923. else
  9924. {
  9925. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9926. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9927. }
  9928. }
  9929. else
  9930. {
  9931. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9932. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9933. }
  9934. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9935. json_object_put(response);
  9936. }
  9937. else
  9938. {
  9939. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9940. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9941. }
  9942. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9943. json_object_put(response);
  9944. }
  9945. else
  9946. {
  9947. // Can not find valid message id
  9948. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9949. }
  9950. }
  9951. else
  9952. {
  9953. // Payload is null
  9954. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9955. }
  9956. LWS_Send(message);
  9957. return result;
  9958. }
  9959. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9960. {
  9961. mtrace();
  9962. int result = FAIL;
  9963. int connectorIdInt, durationInt;
  9964. char chargingRateUnitStr[4]={0};
  9965. char comfirmstr[20];
  9966. int confirmPeriods = 0;
  9967. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9968. json_object *GetCompositeSchedule;
  9969. GetCompositeSchedule = json_tokener_parse(payload);
  9970. if(!is_error(GetCompositeSchedule))
  9971. {
  9972. // Required data
  9973. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9974. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9975. else
  9976. connectorIdInt = -1;
  9977. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9978. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9979. else
  9980. durationInt = 86400;
  9981. // Optional data
  9982. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9983. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9984. }
  9985. json_object_put(GetCompositeSchedule);
  9986. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9987. if((connectorIdInt == 0) ||
  9988. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9989. {
  9990. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9991. struct StructChargingProfile tmpProfile[1];
  9992. if(strstr(chargingRateUnitStr, "W") != NULL)
  9993. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9994. else
  9995. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9996. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9997. {
  9998. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9999. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10000. }
  10001. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10002. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10003. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10004. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10005. {
  10006. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10007. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10008. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10009. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10010. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10011. {
  10012. confirmPeriods = idx;
  10013. break;
  10014. }
  10015. }
  10016. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10017. {
  10018. confirmPeriods += 1;
  10019. }
  10020. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10021. }
  10022. else
  10023. {
  10024. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10025. }
  10026. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10027. return result;
  10028. }
  10029. int handleGetConfigurationRequest(char *uuid, char *payload)
  10030. {
  10031. mtrace();
  10032. int result = FAIL;
  10033. int MaxKeySupported = 0;
  10034. int n_keys = 0;
  10035. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10036. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10037. json_object *GetConfiguration;
  10038. GetConfiguration = json_tokener_parse(payload);
  10039. if(!is_error(GetConfiguration))
  10040. {
  10041. // Optional data
  10042. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10043. {
  10044. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10045. {
  10046. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10047. n_keys = idx + 1;
  10048. }
  10049. }
  10050. }
  10051. json_object_put(GetConfiguration);
  10052. UnknownKeynum = 0;
  10053. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10054. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10055. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10056. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10057. if(n_keys != 0)
  10058. {
  10059. for(int i=0;i<n_keys;i++)
  10060. {
  10061. getKeyValue(requestKey[i]);
  10062. }
  10063. }
  10064. else
  10065. {
  10066. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10067. getKeyValue("");
  10068. }
  10069. processUnkownKey();
  10070. sendGetConfigurationConfirmation(uuid);
  10071. return result;
  10072. }
  10073. static char fnamePlusPath[100]={0};
  10074. static char fnamePWithNoPath[60]={0};
  10075. void checkUploadLog(void)
  10076. {
  10077. FILE *fp;
  10078. /* Open the command for reading. */
  10079. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10080. if (fp == NULL) {
  10081. DEBUG_WARN("Failed to run command\n" );
  10082. exit(1);
  10083. }
  10084. int ftppathlen = 0;
  10085. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10086. int i = 0;
  10087. /* Read the output a line at a time - output it. */
  10088. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10089. if(i==0)
  10090. {
  10091. ftppathlen = strlen(fnamePlusPath);
  10092. DEBUG_INFO("%s\n", fnamePlusPath);
  10093. fnamePlusPath[ftppathlen]='\0';
  10094. break;
  10095. }
  10096. i= i+1;
  10097. }
  10098. /* close */
  10099. pclose(fp);
  10100. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10101. {
  10102. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10103. {
  10104. fnamePlusPath[k]='\0';
  10105. }
  10106. }
  10107. i=1;
  10108. //char fname[60]={0};
  10109. while(i < ftppathlen)
  10110. {
  10111. int len=ftppathlen-i;
  10112. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10113. {
  10114. DEBUG_INFO("compare '/' all right\n");
  10115. break;
  10116. }
  10117. i=i+1;
  10118. }
  10119. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10120. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10121. fnamePWithNoPath[i+1] = '\0';
  10122. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10123. {
  10124. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10125. {
  10126. fnamePWithNoPath[j]='\0';
  10127. }
  10128. }
  10129. FILE* fp1 = fopen(fnamePlusPath, "r");
  10130. if (fp1)
  10131. {
  10132. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10133. // file exists
  10134. fclose(fp1);
  10135. }
  10136. else
  10137. {
  10138. // file doesn't exist
  10139. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10140. }
  10141. }
  10142. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10143. {
  10144. mtrace();
  10145. int result = FAIL;
  10146. time_t CurrentTime;
  10147. struct tm *tm;
  10148. pthread_t th_Status;
  10149. CurrentTime = time(NULL);
  10150. tm = localtime(&CurrentTime);
  10151. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  10152. 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);
  10153. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10154. if(!interLock.isGetDiagnosticGoing)
  10155. {
  10156. interLock.isGetDiagnosticGoing = 1;
  10157. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10158. sleep(1);
  10159. }
  10160. else
  10161. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10162. return result;
  10163. }
  10164. void* GetDiagnosticsProcess(void* data)
  10165. {
  10166. pthread_detach(pthread_self());
  10167. mtrace();
  10168. int retriesInt=0, retryIntervalInt=0;
  10169. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10170. 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};
  10171. int port=0;
  10172. int isSuccess = FALSE;
  10173. char ftpbuf[200]={0};
  10174. char cmdBuf[2048];
  10175. struct tm *tmNow;
  10176. time_t CurrentTime;
  10177. struct tm tmStart;
  10178. struct tm tmStop;
  10179. CurrentTime = time(NULL);
  10180. tmNow=localtime(&CurrentTime);
  10181. uint16_t targetYear, targetMonth;
  10182. json_object *GetDiagnostics;
  10183. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10184. GetDiagnostics = json_tokener_parse(data);
  10185. if(!is_error(GetDiagnostics))
  10186. {
  10187. // Required data
  10188. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10189. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10190. // Optional data
  10191. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10192. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10193. else
  10194. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10195. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10196. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10197. else
  10198. retryIntervalInt = 30;
  10199. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10200. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10201. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10202. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10203. }
  10204. json_object_put(GetDiagnostics);
  10205. // Pack log to compress file
  10206. 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) &&
  10207. (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))
  10208. {
  10209. // Pack system log
  10210. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10211. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10212. targetYear = tmStart.tm_year;
  10213. targetMonth = tmStart.tm_mon;
  10214. do
  10215. {
  10216. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10217. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10218. if(targetMonth+1>=13)
  10219. {
  10220. targetYear += 1;
  10221. targetMonth = 1;
  10222. }
  10223. else
  10224. {
  10225. targetMonth += 1;
  10226. }
  10227. }while((targetYear < (tmNow->tm_year+1900)) ||
  10228. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10229. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10230. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10231. system(cmdBuf);
  10232. // Pack charging & event log
  10233. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10234. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10235. targetYear = tmStart.tm_year;
  10236. targetMonth = tmStart.tm_mon;
  10237. do
  10238. {
  10239. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10240. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10241. if(targetMonth+1>=13)
  10242. {
  10243. targetYear += 1;
  10244. targetMonth = 1;
  10245. }
  10246. else
  10247. {
  10248. targetMonth += 1;
  10249. }
  10250. }while((targetYear < (tmNow->tm_year+1900)) ||
  10251. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10252. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10253. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10254. system(cmdBuf);
  10255. // Combine log file
  10256. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10257. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10258. }
  10259. else
  10260. {
  10261. system("exec /root/logPackTools 'log' 6");
  10262. }
  10263. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10264. system(cmdBuf);
  10265. checkUploadLog();
  10266. //****************location*******************/
  10267. if(strcmp(locationstr,"")==0)
  10268. {
  10269. DEBUG_INFO("location is <Empty>!\n");
  10270. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10271. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10272. goto end;
  10273. }
  10274. memset(protocol, 0, ARRAY_SIZE(protocol));
  10275. memset(user, 0, ARRAY_SIZE(user) );
  10276. memset(password, 0, ARRAY_SIZE(password));
  10277. memset(host, 0, ARRAY_SIZE(host));
  10278. memset(path, 0, ARRAY_SIZE(path));
  10279. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10280. memset(host1, 0, ARRAY_SIZE(host1));
  10281. memset(path1, 0, ARRAY_SIZE(path1));
  10282. /*location: ftp://user:password@host:port/path*/
  10283. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10284. if((access(fnamePlusPath,F_OK))!=-1)
  10285. {
  10286. DEBUG_INFO("fnamePlusPath exist.\n");
  10287. }
  10288. else
  10289. {
  10290. DEBUG_INFO("fnamePlusPath not exist!\n");
  10291. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10292. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10293. goto end;
  10294. }
  10295. if(strchr(locationstr,'@')==NULL)
  10296. {
  10297. sscanf(locationstr,
  10298. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10299. protocol, host, &port, path);
  10300. strcpy(user,"anonymous");
  10301. strcpy(password,"");
  10302. }
  10303. else
  10304. {
  10305. //DEBUG_INFO("pch=%s\n", pch);
  10306. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10307. protocol, user, password, host, &port, path);
  10308. }
  10309. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10310. {
  10311. DEBUG_INFO("protocol is not ftp/http ! \n");
  10312. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10313. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10314. goto end;
  10315. }
  10316. if(strncmp(locationstr,"http", 4) == 0)
  10317. {
  10318. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10319. sprintf(ftppath,"/%s", path);
  10320. do
  10321. {
  10322. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10323. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10324. sleep(3);
  10325. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10326. if(!isSuccess)
  10327. {
  10328. DEBUG_INFO("Diagnostics fail.\n");
  10329. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10330. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10331. sleep(retryIntervalInt);
  10332. }
  10333. else
  10334. {
  10335. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10336. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10337. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10338. }
  10339. retriesInt--;
  10340. }while((isSuccess == 0)&&(retriesInt >= 0));
  10341. }
  10342. else
  10343. {
  10344. sscanf(host,"%[^/]%s",host1, path1);
  10345. if(strlen(path) > 0)
  10346. sprintf(ftppath,"/%s", path);
  10347. else
  10348. sprintf(ftppath,"/%s", path1);
  10349. int ftppathlen=strlen(ftppath);
  10350. int i=1;
  10351. char filenametemp[50];
  10352. while(i < ftppathlen)
  10353. {
  10354. int len=ftppathlen-i;
  10355. if(ftppath[len]== 47) // '/' ascll code: 47
  10356. {
  10357. DEBUG_INFO("find '/' all right\n");
  10358. break;
  10359. }
  10360. i=i+1;
  10361. }
  10362. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10363. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10364. filenametemp[i+1] = 0;
  10365. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10366. if(port == 0)
  10367. port = 21;
  10368. do
  10369. {
  10370. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10371. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10372. sleep(3);
  10373. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10374. if(!isSuccess)
  10375. {
  10376. DEBUG_INFO("Diagnostics fail.\n");
  10377. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10378. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10379. sleep(retryIntervalInt);
  10380. }
  10381. else
  10382. {
  10383. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10384. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10385. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10386. }
  10387. retriesInt--;
  10388. }while((!isSuccess)&&(retriesInt >= 0));
  10389. }
  10390. end:
  10391. system("rm -f /mnt/*");
  10392. sleep(5);
  10393. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10394. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10395. interLock.isGetDiagnosticGoing = 0;
  10396. pthread_exit(NULL);
  10397. }
  10398. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10399. {
  10400. mtrace();
  10401. int result = FAIL;
  10402. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10403. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10404. {
  10405. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10406. locallistVersion = -1;
  10407. }
  10408. else
  10409. {
  10410. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10411. locallistVersion = 0;
  10412. OCPP_getListVerion();
  10413. }
  10414. //from db.OCPP_getListVerion
  10415. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10416. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10417. sendGetLocalListVersionConfirmation(uuid,"");
  10418. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10419. return result;
  10420. }
  10421. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10422. {
  10423. mtrace();
  10424. int result = FAIL;
  10425. int connectorIdInt=-1;
  10426. int tempIndex = 0;
  10427. int connectorIdIsNULL, chargingProfileIsNULL;
  10428. char comfirmstr[20]={0};
  10429. char cmdBuf[512];
  10430. json_object *RemoteStartTransaction;
  10431. FILE *fp;
  10432. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10433. if(server_pending == TRUE)
  10434. {
  10435. return 0;
  10436. }
  10437. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10438. RemoteStartTransaction = json_tokener_parse(payload);
  10439. if(!is_error(RemoteStartTransaction))
  10440. {
  10441. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10442. {
  10443. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10444. }
  10445. else
  10446. {
  10447. connectorIdIsNULL = TRUE;
  10448. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10449. {
  10450. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10451. {
  10452. connectorIdIsNULL = FALSE;
  10453. connectorIdInt = (gun_index+1);
  10454. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10455. break;
  10456. }
  10457. }
  10458. }
  10459. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10460. {
  10461. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10462. // Required data
  10463. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10464. // Optional data
  10465. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10466. {
  10467. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10468. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10469. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10470. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10471. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10472. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10473. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10474. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10475. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10476. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10477. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10478. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10479. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10480. {
  10481. 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")));
  10482. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10483. 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"));
  10484. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10485. 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"));
  10486. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10487. 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")));
  10488. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10489. {
  10490. 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++)
  10491. {
  10492. 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"));
  10493. 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"));
  10494. 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)
  10495. 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"));
  10496. }
  10497. }
  10498. }
  10499. }
  10500. else
  10501. {
  10502. chargingProfileIsNULL = TRUE;
  10503. }
  10504. }
  10505. }
  10506. else
  10507. {
  10508. connectorIdIsNULL = TRUE;
  10509. }
  10510. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10511. {
  10512. DEBUG_WARN("Connector id is NULL\n.");
  10513. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10514. goto end;
  10515. }
  10516. /*
  10517. enum _SYSTEM_STATUS
  10518. {
  10519. S_BOOTING = 0,
  10520. S_IDLE, = 1
  10521. S_AUTHORIZING, = 2
  10522. S_REASSIGN_CHECK, = 3
  10523. S_REASSIGN, = 4
  10524. S_PRECHARGE, = 5
  10525. S_PREPARING_FOR_EV, = 6
  10526. S_PREPARING_FOR_EVSE, = 7
  10527. S_CHARGING, = 8
  10528. S_TERMINATING, = 9
  10529. S_COMPLETE, = 10
  10530. S_ALARM, = 11
  10531. S_FAULT = 12
  10532. }
  10533. */
  10534. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10535. {
  10536. //check Transaction active
  10537. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10538. {
  10539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10540. {
  10541. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10542. }
  10543. else
  10544. {
  10545. tempIndex = connectorIdInt -1;
  10546. }
  10547. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10548. {
  10549. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10550. {
  10551. 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))
  10552. {
  10553. //Reserved
  10554. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10555. }
  10556. 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))
  10557. {
  10558. //Reserved
  10559. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10560. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10561. goto end;
  10562. }
  10563. else
  10564. {
  10565. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10566. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10567. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10568. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10569. {
  10570. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10571. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10572. goto end;
  10573. }
  10574. }//END FOR ELSE
  10575. }
  10576. }// END FOR CHAdeMO_QUANTITY
  10577. }
  10578. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10579. {
  10580. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10581. {
  10582. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10583. }
  10584. else
  10585. {
  10586. tempIndex = connectorIdInt -1;
  10587. }
  10588. for (int index = 0; index < CCS_QUANTITY; index++)
  10589. {
  10590. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10591. {
  10592. 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))
  10593. {
  10594. //Reserved
  10595. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10596. }
  10597. 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))
  10598. {
  10599. //Reserved
  10600. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10601. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10602. goto end;
  10603. }
  10604. else
  10605. {
  10606. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10607. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10608. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10609. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10610. {
  10611. DEBUG_WARN("CCS connector not allow start\n.");
  10612. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10613. goto end;
  10614. }
  10615. }// END FOR ELSE
  10616. }
  10617. }// END FOR CCS_QUANTITY
  10618. }
  10619. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10620. {
  10621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10622. {
  10623. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10624. }
  10625. else
  10626. {
  10627. tempIndex = connectorIdInt -1;
  10628. }
  10629. for (int index = 0; index < GB_QUANTITY; index++)
  10630. {
  10631. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10632. {
  10633. 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))
  10634. {
  10635. //Reserved
  10636. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10637. }
  10638. 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))
  10639. {
  10640. //Reserved
  10641. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10642. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10643. goto end;
  10644. }
  10645. else
  10646. {
  10647. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10648. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10649. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10650. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10651. {
  10652. DEBUG_WARN("GB connector not allow start\n.");
  10653. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10654. goto end;
  10655. }
  10656. }// END FOR ELSE
  10657. }
  10658. } // END FOR GB_QUANTITY
  10659. }
  10660. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10661. {
  10662. tempIndex = connectorIdInt -1;
  10663. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10664. {
  10665. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10666. {
  10667. 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))
  10668. {
  10669. //Reserved
  10670. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10671. }
  10672. 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))
  10673. {
  10674. //Reserved
  10675. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10676. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10677. goto end;
  10678. }
  10679. else
  10680. {
  10681. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10682. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10683. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10684. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10685. {
  10686. DEBUG_WARN("GB connector not allow start\n.");
  10687. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10688. goto end;
  10689. }
  10690. }// END FOR ELSE
  10691. }
  10692. } // END FOR GB_QUANTITY
  10693. }
  10694. else
  10695. {
  10696. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10697. {
  10698. tempIndex = 2;
  10699. }
  10700. else
  10701. {
  10702. tempIndex = connectorIdInt -1;
  10703. }
  10704. for (int index = 0; index < AC_QUANTITY; index++)
  10705. {
  10706. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10707. {
  10708. 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))
  10709. {
  10710. //Reserved
  10711. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10712. }
  10713. 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))
  10714. {
  10715. //Reserved
  10716. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10717. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10718. goto end;
  10719. }
  10720. else
  10721. {
  10722. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10723. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10724. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10725. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10726. {
  10727. DEBUG_WARN("AC connector not allow start\n.");
  10728. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10729. goto end;
  10730. }
  10731. }//END FOR ELSE
  10732. }
  10733. }// END FOR AC_QUANTITY
  10734. }
  10735. if(chargingProfileIsNULL == FALSE)
  10736. {
  10737. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10738. {
  10739. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10740. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10741. //memset idTag
  10742. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10743. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10744. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10746. // Save profile to file
  10747. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10748. system(cmdBuf);
  10749. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10750. fp = fopen(cmdBuf, "w");
  10751. 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));
  10752. fclose(fp);
  10753. }
  10754. else
  10755. {
  10756. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10757. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10758. }
  10759. }
  10760. else
  10761. {
  10762. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10763. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10764. //memset idTag
  10765. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10766. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10767. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10768. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10769. }
  10770. }
  10771. else
  10772. {
  10773. DEBUG_WARN("Connector id over\n.");
  10774. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10775. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10776. }
  10777. end:
  10778. json_object_put(RemoteStartTransaction);
  10779. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10780. {
  10781. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10782. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10783. }
  10784. //OCPP send RemoteStartConfirmation by first.
  10785. sendRemoteStartConfirmation(uuid, comfirmstr);
  10786. return result;
  10787. }
  10788. int handleRemoteStartRequest(char *uuid, char *payload)
  10789. {
  10790. mtrace();
  10791. int result = PASS;
  10792. int connectorIdInt=-1;
  10793. int tempIndex = 0;
  10794. char comfirmstr[20]={0};
  10795. char cmdBuf[512];
  10796. json_object *RemoteStartTransaction;
  10797. FILE *fp;
  10798. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10799. if(server_pending == TRUE)
  10800. {
  10801. result = FAIL;
  10802. }
  10803. RemoteStartTransaction = json_tokener_parse(payload);
  10804. if(!is_error(RemoteStartTransaction))
  10805. {
  10806. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10807. {
  10808. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10809. }
  10810. else
  10811. {
  10812. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10813. {
  10814. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10815. {
  10816. connectorIdInt = (gun_index+1);
  10817. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10818. break;
  10819. }
  10820. }
  10821. }
  10822. if(connectorIdInt == 0)
  10823. {
  10824. DEBUG_WARN("Connector id shall not equal 0.\n");
  10825. result = FAIL;
  10826. }
  10827. else if(connectorIdInt == -1)
  10828. {
  10829. DEBUG_INFO("Connector id does not specific.\n");
  10830. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10831. {
  10832. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10833. // Required data
  10834. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10835. // Optional data
  10836. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10837. {
  10838. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10839. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10840. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10841. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10842. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10843. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10844. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10845. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10846. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10847. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10848. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10849. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10850. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10851. {
  10852. 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")));
  10853. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10854. 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"));
  10855. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10856. 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"));
  10857. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10858. 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")));
  10859. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10860. {
  10861. 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++)
  10862. {
  10863. 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"));
  10864. 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"));
  10865. 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)
  10866. 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"));
  10867. }
  10868. }
  10869. }
  10870. }
  10871. else
  10872. {
  10873. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10874. }
  10875. }
  10876. }
  10877. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10878. {
  10879. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10880. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10881. // Required data
  10882. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10883. // Optional data
  10884. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10885. {
  10886. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10887. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10888. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10889. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10890. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10891. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10892. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10893. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10894. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10895. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10896. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10897. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10898. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10899. {
  10900. 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")));
  10901. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10902. 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"));
  10903. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10904. 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"));
  10905. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10906. 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")));
  10907. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10908. {
  10909. 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++)
  10910. {
  10911. 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"));
  10912. 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"));
  10913. 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)
  10914. 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"));
  10915. }
  10916. }
  10917. }
  10918. }
  10919. else
  10920. {
  10921. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10922. }
  10923. }
  10924. else
  10925. {
  10926. DEBUG_WARN("Connector id is over maximun value.\n");
  10927. result = FAIL;
  10928. }
  10929. }
  10930. if(result == PASS)
  10931. {
  10932. if(connectorIdInt > 0)
  10933. {
  10934. //check Transaction active
  10935. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10936. {
  10937. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10938. {
  10939. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10940. }
  10941. else
  10942. {
  10943. tempIndex = connectorIdInt -1;
  10944. }
  10945. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10946. {
  10947. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10948. {
  10949. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10950. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10951. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10952. {
  10953. //Reserved
  10954. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10955. }
  10956. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10957. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10958. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10959. {
  10960. //Reserved
  10961. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10962. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10963. goto end;
  10964. }
  10965. else
  10966. {
  10967. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10968. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10969. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10970. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10971. {
  10972. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10973. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10974. goto end;
  10975. }
  10976. }//END FOR ELSE
  10977. }
  10978. }// END FOR CHAdeMO_QUANTITY
  10979. }
  10980. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10981. {
  10982. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10983. {
  10984. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10985. }
  10986. else
  10987. {
  10988. tempIndex = connectorIdInt -1;
  10989. }
  10990. for (int index = 0; index < CCS_QUANTITY; index++)
  10991. {
  10992. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10993. {
  10994. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10995. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10996. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10997. {
  10998. //Reserved
  10999. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11000. }
  11001. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11002. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11003. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11004. {
  11005. //Reserved
  11006. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11007. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11008. goto end;
  11009. }
  11010. else
  11011. {
  11012. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11013. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11014. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11015. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11016. {
  11017. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11018. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11019. goto end;
  11020. }
  11021. }// END FOR ELSE
  11022. }
  11023. }// END FOR CCS_QUANTITY
  11024. }
  11025. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11026. {
  11027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11028. {
  11029. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11030. }
  11031. else
  11032. {
  11033. tempIndex = connectorIdInt -1;
  11034. }
  11035. for (int index = 0; index < GB_QUANTITY; index++)
  11036. {
  11037. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11038. {
  11039. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11040. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11041. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11042. {
  11043. //Reserved
  11044. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11045. }
  11046. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11047. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11048. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11049. {
  11050. //Reserved
  11051. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11052. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11053. goto end;
  11054. }
  11055. else
  11056. {
  11057. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11058. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11059. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11060. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11061. {
  11062. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11063. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11064. goto end;
  11065. }
  11066. }// END FOR ELSE
  11067. }
  11068. } // END FOR GB_QUANTITY
  11069. }
  11070. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11071. {
  11072. tempIndex = connectorIdInt -1;
  11073. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11074. {
  11075. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11076. {
  11077. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11078. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11079. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11080. {
  11081. //Reserved
  11082. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11083. }
  11084. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11085. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11086. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11087. {
  11088. //Reserved
  11089. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11090. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11091. goto end;
  11092. }
  11093. else
  11094. {
  11095. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11096. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11097. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11098. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11099. {
  11100. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11101. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11102. goto end;
  11103. }
  11104. }// END FOR ELSE
  11105. }
  11106. } // END FOR GB_QUANTITY
  11107. }
  11108. else
  11109. {
  11110. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11111. {
  11112. tempIndex = 2;
  11113. }
  11114. else
  11115. {
  11116. tempIndex = connectorIdInt -1;
  11117. }
  11118. for (int index = 0; index < AC_QUANTITY; index++)
  11119. {
  11120. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11121. {
  11122. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11123. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11124. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11125. {
  11126. //Reserved
  11127. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11128. }
  11129. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11130. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11131. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11132. {
  11133. //Reserved
  11134. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11135. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11136. goto end;
  11137. }
  11138. else
  11139. {
  11140. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11141. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11142. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11143. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11144. {
  11145. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11146. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11147. goto end;
  11148. }
  11149. }//END FOR ELSE
  11150. }
  11151. }// END FOR AC_QUANTITY
  11152. }
  11153. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11154. {
  11155. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11156. {
  11157. // Save profile to file
  11158. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  11159. system(cmdBuf);
  11160. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  11161. fp = fopen(cmdBuf, "w");
  11162. 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));
  11163. fclose(fp);
  11164. }
  11165. else
  11166. {
  11167. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11168. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11169. goto end;
  11170. }
  11171. }
  11172. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11173. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11174. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11175. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11176. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11177. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11178. }
  11179. else
  11180. {
  11181. uint8_t isHasIdleConnector = FALSE;
  11182. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11183. {
  11184. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11185. {
  11186. isHasIdleConnector = TRUE;
  11187. break;
  11188. }
  11189. }
  11190. if(isHasIdleConnector == TRUE)
  11191. {
  11192. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11193. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11194. {
  11195. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11196. {
  11197. // Save profile to file
  11198. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  11199. system(cmdBuf);
  11200. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  11201. fp = fopen(cmdBuf, "w");
  11202. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11203. fclose(fp);
  11204. refreshStartTimer(&clientTime.RemoteStartWait);
  11205. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  11206. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11207. }
  11208. else
  11209. {
  11210. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11211. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11212. }
  11213. }
  11214. else
  11215. {
  11216. refreshStartTimer(&clientTime.RemoteStartWait);
  11217. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  11218. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11219. }
  11220. }
  11221. else
  11222. {
  11223. DEBUG_INFO("There is not any connector is idle.\n");
  11224. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11225. }
  11226. }
  11227. }
  11228. else
  11229. {
  11230. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11231. }
  11232. end:
  11233. json_object_put(RemoteStartTransaction);
  11234. sendRemoteStartConfirmation(uuid, comfirmstr);
  11235. return result;
  11236. }
  11237. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11238. {
  11239. mtrace();
  11240. int result = FAIL;
  11241. int match = FALSE;
  11242. int GunNO = 0;
  11243. int tempIndex = 0;
  11244. int transactionIdInt=0;
  11245. int transactionIdIsNULL= TRUE;
  11246. char comfirmstr[20];
  11247. json_object *RemoteStopTransaction;
  11248. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11249. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11250. if(server_pending == TRUE)
  11251. {
  11252. return 0;
  11253. }
  11254. RemoteStopTransaction = json_tokener_parse(payload);
  11255. if(!is_error(RemoteStopTransaction))
  11256. {
  11257. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11258. {
  11259. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11260. transactionIdIsNULL = FALSE;
  11261. }
  11262. }
  11263. json_object_put(RemoteStopTransaction);
  11264. if(transactionIdIsNULL == FALSE)
  11265. {
  11266. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11267. {
  11268. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11269. {
  11270. //check Transaction active
  11271. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11272. {
  11273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11274. {
  11275. tempIndex = ((gun_index==2) ? 1: 0);
  11276. }
  11277. else
  11278. {
  11279. tempIndex = gun_index;
  11280. }
  11281. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11282. {
  11283. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11284. {
  11285. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11286. {
  11287. match = TRUE;
  11288. GunNO = gun_index;
  11289. }
  11290. }
  11291. }// END FOR CHAdeMO_QUANTITY
  11292. }
  11293. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11294. {
  11295. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11296. {
  11297. tempIndex = ((gun_index==2) ? 1: 0);
  11298. }
  11299. else
  11300. {
  11301. tempIndex = gun_index;
  11302. }
  11303. for (int index = 0; index < CCS_QUANTITY; index++)
  11304. {
  11305. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11306. {
  11307. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11308. {
  11309. match = TRUE;
  11310. GunNO = gun_index;
  11311. }
  11312. }
  11313. }// END FOR CCS_QUANTITY
  11314. }
  11315. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11316. {
  11317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11318. {
  11319. tempIndex = ((gun_index==2) ? 1: 0);
  11320. }
  11321. else
  11322. {
  11323. tempIndex = gun_index;
  11324. }
  11325. for (int index = 0; index < GB_QUANTITY; index++)
  11326. {
  11327. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11328. {
  11329. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11330. {
  11331. match = TRUE;
  11332. GunNO = gun_index;
  11333. }
  11334. }
  11335. }// END FOR GB_QUANTITY
  11336. }
  11337. else if(gunType[gun_index] == GUN_TYPE_DO)
  11338. {
  11339. tempIndex = gun_index;
  11340. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11341. {
  11342. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11343. {
  11344. 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
  11345. {
  11346. match = TRUE;
  11347. GunNO = gun_index;
  11348. }
  11349. }
  11350. }// END FOR GB_QUANTITY
  11351. }
  11352. else
  11353. {
  11354. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11355. {
  11356. tempIndex = 2;
  11357. }
  11358. else
  11359. {
  11360. tempIndex = gun_index;
  11361. }
  11362. for (int index = 0; index < AC_QUANTITY; index++)
  11363. {
  11364. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11365. {
  11366. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11367. {
  11368. match = TRUE;
  11369. GunNO = gun_index;
  11370. }
  11371. }
  11372. }// END FOR CHAdeMO_QUANTITY
  11373. } // END FOR AC ELSE
  11374. }// CHECK IF ResponseTransactionId == transactionIdInt
  11375. }//END FOR
  11376. if( match == TRUE)
  11377. {
  11378. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11379. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11380. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11381. }
  11382. else
  11383. {
  11384. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11385. }
  11386. }
  11387. else
  11388. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11389. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11390. return result;
  11391. }
  11392. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11393. {
  11394. mtrace();
  11395. int result = FAIL;
  11396. int connectorIdInt=0, reservationIdInt=0;
  11397. int tempIndex = 0;
  11398. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11399. char comfirmstr[20]={0};
  11400. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11401. int c = 0;
  11402. char *loc;
  11403. //char *ptr;
  11404. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11405. strcpy(sstrtemp, stringtrimspace(payload));
  11406. //***(1)connectorId ****/
  11407. c=0;
  11408. loc = strstr(sstrtemp, "connectorId");
  11409. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11410. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11411. {
  11412. sstr[c] = loc[strlen("connectorId")+2+c];
  11413. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11414. c++;
  11415. }
  11416. sstr[c] = '\0';
  11417. connectorIdInt = atoi(sstr);
  11418. //***(2)expiryDate ****/
  11419. loc = strstr(sstrtemp, "expiryDate");
  11420. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11421. c = 0;
  11422. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11423. {
  11424. sstr[c] = loc[3+strlen("expiryDate")+c];
  11425. c++;
  11426. }
  11427. sstr[c] = '\0';
  11428. strcpy(expiryDatestr, sstr);
  11429. //***(3)idTag ****/
  11430. loc = strstr(sstrtemp, "idTag");
  11431. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11432. c = 0;
  11433. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11434. {
  11435. sstr[c] = loc[3+strlen("idTag")+c];
  11436. c++;
  11437. }
  11438. sstr[c] = '\0';
  11439. strcpy(idTagstr, sstr);
  11440. //***(4)parentIdTag ****/
  11441. loc = strstr(sstrtemp, "parentIdTag");
  11442. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11443. c = 0;
  11444. if(loc == NULL)
  11445. {
  11446. strcpy(parentIdTagstr, "");
  11447. }
  11448. else
  11449. {
  11450. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11451. {
  11452. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11453. c++;
  11454. }
  11455. sstr[c] = '\0';
  11456. strcpy(parentIdTagstr, sstr);
  11457. }
  11458. //***(5)reservationId ****/
  11459. c=0;
  11460. loc = strstr(sstrtemp, "reservationId");
  11461. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11462. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11463. {
  11464. sstr[c] = loc[strlen("reservationId")+2+c];
  11465. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11466. c++;
  11467. }
  11468. sstr[c] = '\0';
  11469. reservationIdInt = atoi(sstr);
  11470. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11471. /*
  11472. enum SYSTEM_STATUS
  11473. {
  11474. SYS_MODE_BOOTING = 0,
  11475. SYS_MODE_IDLE = 1,
  11476. SYS_MODE_AUTHORIZING = 2,
  11477. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11478. SYS_MODE_REASSIGN = 4,
  11479. SYS_MODE_PREPARING = 5,
  11480. SYS_MODE_PREPARE_FOR_EV = 6,
  11481. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11482. SYS_MODE_CHARGING = 8,
  11483. SYS_MODE_TERMINATING = 9,
  11484. SYS_MODE_COMPLETE = 10,
  11485. SYS_MODE_ALARM = 11,
  11486. SYS_MODE_FAULT = 12,
  11487. SYS_MODE_RESERVATION = 13,
  11488. SYS_MODE_BOOKING = 14,
  11489. SYS_MODE_MAINTAIN = 15,
  11490. SYS_MODE_DEBUG = 16,
  11491. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11492. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11493. SYS_MODE_UPDATE = 19
  11494. };
  11495. */
  11496. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11497. {
  11498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11499. goto end;
  11500. }
  11501. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11502. {
  11503. //check Transaction active
  11504. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11505. {
  11506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11507. {
  11508. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11509. }
  11510. else
  11511. {
  11512. tempIndex = connectorIdInt -1;
  11513. }
  11514. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11515. {
  11516. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11517. {
  11518. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11519. {
  11520. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11521. {
  11522. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11523. {
  11524. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11525. {
  11526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11527. }
  11528. else
  11529. {
  11530. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11532. }
  11533. }
  11534. 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'))
  11535. {
  11536. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11537. }
  11538. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11539. {
  11540. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11541. }
  11542. else
  11543. {
  11544. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11545. }
  11546. }
  11547. 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
  11548. {
  11549. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11550. }
  11551. }
  11552. else
  11553. {
  11554. //replace reservation
  11555. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11556. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11557. }
  11558. }
  11559. } // END FOR CHAdeMO_QUANTITY
  11560. }
  11561. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11562. {
  11563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11564. {
  11565. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11566. }
  11567. else
  11568. {
  11569. tempIndex = connectorIdInt -1;
  11570. }
  11571. for (int index = 0; index < CCS_QUANTITY; index++)
  11572. {
  11573. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11574. {
  11575. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11576. {
  11577. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11578. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11579. {
  11580. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11581. {
  11582. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11583. {
  11584. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11585. }
  11586. else
  11587. {
  11588. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11589. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11590. }
  11591. }
  11592. 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'))
  11593. {
  11594. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11595. }
  11596. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11597. {
  11598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11599. }
  11600. else
  11601. {
  11602. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11603. }
  11604. }
  11605. 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
  11606. {
  11607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11608. }
  11609. }
  11610. else
  11611. {
  11612. //replace reservation
  11613. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11615. }
  11616. }
  11617. } // END FOR CCS_QUANTITY
  11618. }
  11619. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11620. {
  11621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11622. {
  11623. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11624. }
  11625. else
  11626. {
  11627. tempIndex = connectorIdInt -1;
  11628. }
  11629. for (int index = 0; index < GB_QUANTITY; index++)
  11630. {
  11631. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11632. {
  11633. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11634. {
  11635. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11636. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11637. {
  11638. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11639. {
  11640. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11641. {
  11642. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11643. }
  11644. else
  11645. {
  11646. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11647. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11648. }
  11649. }
  11650. 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'))
  11651. {
  11652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11653. }
  11654. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11655. {
  11656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11657. }
  11658. else
  11659. {
  11660. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11661. }
  11662. }
  11663. 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
  11664. {
  11665. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11666. }
  11667. }
  11668. else
  11669. {
  11670. //replace reservation
  11671. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11673. }
  11674. }
  11675. }// END FOR GB_QUANTITY
  11676. }
  11677. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11678. {
  11679. tempIndex = connectorIdInt -1;
  11680. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11681. {
  11682. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11683. {
  11684. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11685. {
  11686. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11687. 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
  11688. {
  11689. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11690. {
  11691. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11692. {
  11693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11694. }
  11695. else
  11696. {
  11697. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11698. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11699. }
  11700. }
  11701. 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'))
  11702. {
  11703. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11704. }
  11705. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11706. {
  11707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11708. }
  11709. else
  11710. {
  11711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11712. }
  11713. }
  11714. 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
  11715. {
  11716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11717. }
  11718. }
  11719. else
  11720. {
  11721. //replace reservation
  11722. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11724. }
  11725. }
  11726. }// END FOR GB_QUANTITY
  11727. }
  11728. else
  11729. {
  11730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11731. {
  11732. tempIndex = 2;
  11733. }
  11734. else
  11735. {
  11736. tempIndex = (connectorIdInt -1);
  11737. }
  11738. for (int index = 0; index < AC_QUANTITY; index++)
  11739. {
  11740. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11741. {
  11742. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11743. {
  11744. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11745. {
  11746. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11747. {
  11748. 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))
  11749. {
  11750. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11751. }
  11752. else
  11753. {
  11754. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11755. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11756. }
  11757. }
  11758. 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'))
  11759. {
  11760. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11761. }
  11762. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11763. {
  11764. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11765. }
  11766. else
  11767. {
  11768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11769. }
  11770. }
  11771. 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
  11772. {
  11773. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11774. }
  11775. }
  11776. else
  11777. {
  11778. //replace reservation
  11779. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11781. }
  11782. }
  11783. } // END FOR AC_QUANTITY
  11784. }
  11785. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11786. }
  11787. else if(connectorIdInt == 0)
  11788. {
  11789. //check Transaction active
  11790. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11791. {
  11792. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11793. {
  11794. 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'))
  11795. {
  11796. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11797. goto end;
  11798. }
  11799. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11800. {
  11801. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11802. goto end;
  11803. }
  11804. 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
  11805. {
  11806. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11807. goto end;
  11808. }
  11809. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11810. {
  11811. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11812. goto end;
  11813. }
  11814. }
  11815. }// END FOR CHAdeMO_QUANTITY
  11816. for (int index = 0; index < CCS_QUANTITY; index++)
  11817. {
  11818. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11819. {
  11820. 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'))
  11821. {
  11822. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11823. goto end;
  11824. }
  11825. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11826. {
  11827. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11828. goto end;
  11829. }
  11830. 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
  11831. {
  11832. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11833. goto end;
  11834. }
  11835. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11836. {
  11837. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11838. goto end;
  11839. }
  11840. }
  11841. } // END FOR CCS_QUANTITY
  11842. for (int index = 0; index < GB_QUANTITY; index++)
  11843. {
  11844. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11845. {
  11846. 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'))
  11847. {
  11848. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11849. goto end;
  11850. }
  11851. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11852. {
  11853. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11854. goto end;
  11855. }
  11856. 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
  11857. {
  11858. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11859. goto end;
  11860. }
  11861. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11862. {
  11863. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11864. goto end;
  11865. }
  11866. }
  11867. } // END FOR GB_QUANTITY
  11868. for (int index = 0; index < AC_QUANTITY; index++)
  11869. {
  11870. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11871. {
  11872. 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'))
  11873. {
  11874. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11875. goto end;
  11876. }
  11877. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11878. {
  11879. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11880. goto end;
  11881. }
  11882. 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
  11883. {
  11884. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11885. goto end;
  11886. }
  11887. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11888. {
  11889. 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))
  11890. {
  11891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11892. goto end;
  11893. }
  11894. }
  11895. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11896. {
  11897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11898. goto end;
  11899. }
  11900. }
  11901. }// END FOR AC_QUANTITY
  11902. //The connectorId is 0
  11903. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11905. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11906. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11907. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11908. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11909. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11910. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11911. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11912. result = TRUE;
  11913. return result;
  11914. }
  11915. else
  11916. {
  11917. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11918. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11919. }
  11920. if(strcmp(comfirmstr,"Accepted") == 0)
  11921. {
  11922. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11923. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11924. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11925. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11926. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11927. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11928. result = TRUE;
  11929. return result;
  11930. }
  11931. end:
  11932. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11933. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11934. return result;
  11935. }
  11936. int handleResetRequest(char *uuid, char *payload)
  11937. {
  11938. mtrace();
  11939. int result = FAIL;
  11940. char sstr[10]={0},sstrtemp[30]={ 0 };
  11941. char typestr[10]={0};
  11942. char comfirmstr[20]={0};
  11943. int c = 0;
  11944. char *loc;
  11945. DEBUG_INFO("handleResetRequest...\n");
  11946. strcpy(sstrtemp, stringtrimspace(payload));
  11947. loc = strstr(sstrtemp, "type");
  11948. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11949. c = 0;
  11950. while (loc[3+strlen("type")+c] != '\"')
  11951. {
  11952. sstr[c] = loc[3+strlen("type")+c];
  11953. c++;
  11954. }
  11955. sstr[c] = '\0';
  11956. strcpy(typestr,sstr);
  11957. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11958. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11959. {
  11960. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11961. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11962. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11963. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11964. }
  11965. else
  11966. {
  11967. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11968. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11969. result = PASS;
  11970. }
  11971. sendResetConfirmation(uuid, comfirmstr);
  11972. return result;
  11973. }
  11974. int handleSendLocalListRequest(char *uuid, char *payload)
  11975. {
  11976. mtrace();
  11977. int result = FAIL;
  11978. char comfirmstr[20];
  11979. int checkState_Faulted = FALSE;
  11980. json_object *SendLocalList;
  11981. DEBUG_INFO("handleSendLocalListRequest...\n");
  11982. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11983. {
  11984. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11985. goto end;
  11986. }
  11987. //check Charge Point state
  11988. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11989. {
  11990. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11991. {
  11992. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11993. }
  11994. }
  11995. for (int index = 0; index < CCS_QUANTITY; index++)
  11996. {
  11997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11998. {
  11999. checkState_Faulted = TRUE; //OCPP Status
  12000. }
  12001. }
  12002. for (int index = 0; index < GB_QUANTITY; index++)
  12003. {
  12004. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12005. {
  12006. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12007. }
  12008. }
  12009. //check Charge Point state
  12010. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12011. {
  12012. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12013. {
  12014. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12015. }
  12016. }
  12017. //check Charge Point state
  12018. for (int index = 0; index < AC_QUANTITY; index++)
  12019. {
  12020. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12021. {
  12022. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12023. }
  12024. }
  12025. if(checkState_Faulted == TRUE)
  12026. {
  12027. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12028. goto end;
  12029. }
  12030. // Parsing payload
  12031. SendLocalList = json_tokener_parse(payload);
  12032. if(!is_error(SendLocalList))
  12033. {
  12034. // Required data
  12035. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12036. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12037. // Optional data
  12038. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12039. {
  12040. //Check UpdateType
  12041. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12042. {
  12043. //Local list full update
  12044. DEBUG_INFO("Local list full update.\n");
  12045. locallistVersion = 0;
  12046. OCPP_getListVerion();
  12047. /*if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  12048. {
  12049. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12050. goto end;
  12051. }*/
  12052. OCPP_cleanLocalList();
  12053. }
  12054. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12055. {
  12056. //Local list different update
  12057. DEBUG_INFO("Local list different update.\n");
  12058. locallistVersion = 0;
  12059. OCPP_getListVerion();
  12060. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  12061. {
  12062. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12063. goto end;
  12064. }
  12065. }
  12066. else
  12067. {
  12068. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12069. goto end;
  12070. }
  12071. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12072. {
  12073. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12074. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12075. goto end;
  12076. }
  12077. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12078. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12079. {
  12080. 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")));
  12081. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12082. {
  12083. 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")));
  12084. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12085. 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")));
  12086. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12087. 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")));
  12088. }
  12089. // Add to db
  12090. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12091. {
  12092. //Local list full update
  12093. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12094. idx,
  12095. ShmOCPP16DataPH->SendLocalList.ListVersion,
  12096. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12097. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12098. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12099. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12100. // update list
  12101. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  12102. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12103. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12104. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12105. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12106. }
  12107. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12108. {
  12109. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12110. idx,
  12111. ShmOCPP16DataPH->SendLocalList.ListVersion,
  12112. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12113. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12114. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12115. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12116. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  12117. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12118. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12119. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12120. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12121. }
  12122. }
  12123. }
  12124. else
  12125. {
  12126. //Check UpdateType
  12127. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12128. {
  12129. //Local list full update
  12130. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12131. OCPP_cleanLocalList();
  12132. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12133. goto end;
  12134. }
  12135. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12136. {
  12137. //Local list different update
  12138. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12139. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12140. goto end;
  12141. }
  12142. }
  12143. result = PASS;
  12144. }
  12145. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12146. end:
  12147. json_object_put(SendLocalList);
  12148. sendSendLocalListConfirmation(uuid, comfirmstr);
  12149. return result;
  12150. }
  12151. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12152. {
  12153. mtrace();
  12154. int result = FAIL;
  12155. struct StructSetChargingProfile SetProfileReq = {0};
  12156. int tempchargingProfileIdInt;
  12157. int tempstackLevelInt;
  12158. int chargingSchedulePeriodCount = 0;
  12159. char comfirmstr[20]={0};
  12160. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  12161. char rmFileCmd[128]={0};
  12162. int profileQuantity = 0;
  12163. int replaceableProfileCnt = 0;
  12164. json_object *SetChargingProfile;
  12165. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12166. SetChargingProfile = json_tokener_parse(payload);
  12167. if(!is_error(SetChargingProfile))
  12168. {
  12169. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12170. {
  12171. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12172. }
  12173. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12174. {
  12175. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12176. {
  12177. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12178. }
  12179. else
  12180. {
  12181. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12182. DEBUG_WARN("Cannot find chargingProfileId field.");
  12183. goto end;
  12184. }
  12185. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12186. {
  12187. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12188. }
  12189. else
  12190. {
  12191. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12192. DEBUG_WARN("Cannot find stackLevel field.");
  12193. goto end;
  12194. }
  12195. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12196. {
  12197. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12198. }
  12199. else
  12200. {
  12201. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12202. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12203. goto end;
  12204. }
  12205. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12206. {
  12207. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12208. }
  12209. else
  12210. {
  12211. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12212. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12213. goto end;
  12214. }
  12215. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12216. {
  12217. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12218. }
  12219. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12220. {
  12221. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12222. }
  12223. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12224. {
  12225. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12226. }
  12227. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12228. {
  12229. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12230. }
  12231. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12232. {
  12233. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12234. {
  12235. 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")));
  12236. }
  12237. else
  12238. {
  12239. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12240. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12241. goto end;
  12242. }
  12243. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12244. {
  12245. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12246. }
  12247. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12248. {
  12249. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12250. }
  12251. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12252. {
  12253. 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")));
  12254. }
  12255. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12256. {
  12257. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12258. if(chargingSchedulePeriodCount <= 10)
  12259. {
  12260. 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++)
  12261. {
  12262. 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)
  12263. {
  12264. 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"));
  12265. }
  12266. else
  12267. {
  12268. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12269. DEBUG_WARN("Cannot find startPeriod field.");
  12270. goto end;
  12271. }
  12272. 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)
  12273. {
  12274. 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"));
  12275. }
  12276. else
  12277. {
  12278. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12279. DEBUG_WARN("Cannot find limit field.");
  12280. goto end;
  12281. }
  12282. 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)
  12283. {
  12284. 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"));
  12285. }
  12286. }
  12287. }
  12288. }
  12289. else
  12290. {
  12291. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12292. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12293. goto end;
  12294. }
  12295. }
  12296. else
  12297. {
  12298. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12299. DEBUG_WARN("Cannot find chargingSchedule field.");
  12300. goto end;
  12301. }
  12302. }
  12303. }
  12304. // Profile periods quantity check
  12305. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12306. {
  12307. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12308. goto end;
  12309. }
  12310. // Check invalid limit
  12311. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12312. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12313. {
  12314. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12315. {
  12316. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12317. {
  12318. 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)))) ||
  12319. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12320. {
  12321. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12322. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12323. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12324. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12325. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12326. goto end;
  12327. }
  12328. }
  12329. }
  12330. else
  12331. {
  12332. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12333. {
  12334. 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) ||
  12335. (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)))
  12336. {
  12337. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12338. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12339. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12340. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12341. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12342. goto end;
  12343. }
  12344. }
  12345. }
  12346. }
  12347. // Profile purpose info check
  12348. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12349. {
  12350. FILE *fp;
  12351. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12352. if(SetProfileReq.ConnectorId != 0)
  12353. {
  12354. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12355. goto end;
  12356. }
  12357. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12358. if (!fp)
  12359. {
  12360. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12361. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12362. }
  12363. else
  12364. {
  12365. char *line = NULL;
  12366. size_t len = 0;
  12367. while(getline(&line, &len, fp) != -1)
  12368. {
  12369. json_object *obj = NULL;
  12370. obj = json_tokener_parse(line);
  12371. if(is_error(obj))
  12372. {
  12373. DEBUG_ERROR("Parse txProfile from file error.\n");
  12374. }
  12375. else
  12376. {
  12377. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12378. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12379. {
  12380. profileQuantity += 1;
  12381. }
  12382. else
  12383. replaceableProfileCnt += 1;
  12384. }
  12385. }
  12386. }
  12387. fclose(fp);
  12388. }
  12389. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12390. {
  12391. FILE *fp;
  12392. char filename[128]={0};
  12393. int tmpProfileQuantity;
  12394. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12395. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12396. {
  12397. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12398. goto end;
  12399. }
  12400. if(SetProfileReq.ConnectorId == 0)
  12401. {
  12402. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12403. {
  12404. tmpProfileQuantity = 0;
  12405. memset(filename, 0, ARRAY_SIZE(filename));
  12406. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12407. fp = fopen(filename, "r");
  12408. if (!fp)
  12409. {
  12410. DEBUG_INFO("%s does not create.\n", filename);
  12411. fp = fopen(filename, "w+");
  12412. }
  12413. else
  12414. {
  12415. char *line = NULL;
  12416. size_t len = 0;
  12417. while(getline(&line, &len, fp) != -1)
  12418. {
  12419. json_object *obj = NULL;
  12420. obj = json_tokener_parse(line);
  12421. if(is_error(obj))
  12422. {
  12423. DEBUG_ERROR("Parse txProfile from file error.\n");
  12424. }
  12425. else
  12426. {
  12427. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12428. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12429. {
  12430. tmpProfileQuantity += 1;
  12431. }
  12432. else
  12433. replaceableProfileCnt += 1;
  12434. }
  12435. }
  12436. }
  12437. fclose(fp);
  12438. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12439. }
  12440. }
  12441. else
  12442. {
  12443. memset(filename, 0, ARRAY_SIZE(filename));
  12444. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12445. fp = fopen(filename, "r");
  12446. if (!fp)
  12447. {
  12448. DEBUG_INFO("%s does not create.\n", filename);
  12449. fp = fopen(filename, "w+");
  12450. }
  12451. else
  12452. {
  12453. char *line = NULL;
  12454. size_t len = 0;
  12455. while(getline(&line, &len, fp) != -1)
  12456. {
  12457. json_object *obj = NULL;
  12458. obj = json_tokener_parse(line);
  12459. if(is_error(obj))
  12460. {
  12461. DEBUG_ERROR("Parse txProfile from file error.\n");
  12462. }
  12463. else
  12464. {
  12465. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12466. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12467. {
  12468. profileQuantity += 1;
  12469. }
  12470. else
  12471. replaceableProfileCnt += 1;
  12472. }
  12473. }
  12474. }
  12475. fclose(fp);
  12476. }
  12477. }
  12478. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12479. {
  12480. int isMatchTransactiodId= FALSE;
  12481. FILE *fp;
  12482. char filename[128]={0};
  12483. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12484. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12485. if(SetProfileReq.ConnectorId == 0)
  12486. {
  12487. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12488. goto end;
  12489. }
  12490. int tempIndex = 0;
  12491. //check Transaction active
  12492. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12493. {
  12494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12495. {
  12496. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12497. }
  12498. else
  12499. {
  12500. tempIndex = SetProfileReq.ConnectorId -1;
  12501. }
  12502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12503. {
  12504. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12505. {
  12506. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12507. {
  12508. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12509. {
  12510. isMatchTransactiodId = TRUE;
  12511. break;
  12512. }
  12513. }
  12514. }
  12515. }
  12516. }
  12517. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12518. {
  12519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12520. {
  12521. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12522. }
  12523. else
  12524. {
  12525. tempIndex = SetProfileReq.ConnectorId -1;
  12526. }
  12527. for (int index = 0; index < CCS_QUANTITY; index++)
  12528. {
  12529. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12530. {
  12531. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12532. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12533. {
  12534. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12535. {
  12536. isMatchTransactiodId = TRUE;
  12537. break;
  12538. }
  12539. }
  12540. }
  12541. }
  12542. }
  12543. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12544. {
  12545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12546. {
  12547. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12548. }
  12549. else
  12550. {
  12551. tempIndex = SetProfileReq.ConnectorId -1;
  12552. }
  12553. for (int index = 0; index < GB_QUANTITY; index++)
  12554. {
  12555. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12556. {
  12557. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12558. {
  12559. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12560. {
  12561. isMatchTransactiodId = TRUE;
  12562. break;
  12563. }
  12564. }
  12565. }
  12566. }
  12567. }
  12568. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12569. {
  12570. tempIndex = SetProfileReq.ConnectorId -1;
  12571. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12572. {
  12573. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12574. {
  12575. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12576. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12577. {
  12578. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12579. {
  12580. isMatchTransactiodId = TRUE;
  12581. break;
  12582. }
  12583. }
  12584. }
  12585. }
  12586. }
  12587. else
  12588. {
  12589. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12590. {
  12591. tempIndex = 2;
  12592. }
  12593. else
  12594. {
  12595. tempIndex = (SetProfileReq.ConnectorId -1);
  12596. }
  12597. for (int index = 0; index < AC_QUANTITY; index++)
  12598. {
  12599. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12600. {
  12601. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12602. {
  12603. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12604. {
  12605. isMatchTransactiodId = TRUE;
  12606. break;
  12607. }
  12608. }
  12609. }
  12610. }
  12611. }
  12612. //check Transaction active
  12613. if(isMatchTransactiodId == FALSE)
  12614. {
  12615. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12616. goto end;
  12617. }
  12618. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12619. {
  12620. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12621. goto end;
  12622. }
  12623. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12624. fp = fopen(filename, "r");
  12625. if (!fp)
  12626. {
  12627. DEBUG_INFO("%s does not create.\n", filename);
  12628. fp = fopen(filename, "w+");
  12629. }
  12630. else
  12631. {
  12632. char *line = NULL;
  12633. size_t len = 0;
  12634. while(getline(&line, &len, fp) != -1)
  12635. {
  12636. json_object *obj = NULL;
  12637. obj = json_tokener_parse(line);
  12638. if(is_error(obj))
  12639. {
  12640. DEBUG_ERROR("Parse txProfile from file error.\n");
  12641. }
  12642. else
  12643. {
  12644. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12645. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12646. {
  12647. profileQuantity += 1;
  12648. }
  12649. else
  12650. replaceableProfileCnt += 1;
  12651. }
  12652. }
  12653. }
  12654. fclose(fp);
  12655. }
  12656. // Check ChargeProfileMaxStackLevel
  12657. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12658. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12659. {
  12660. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12661. goto end;
  12662. }
  12663. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12664. {
  12665. FILE *fp;
  12666. char dataLine[4096]={0};
  12667. char fnametemp[128]={0};
  12668. int tmpProfileQuantity;
  12669. //Check ChargePointMaxProfile.json exit
  12670. profileQuantity = 0;
  12671. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12672. {
  12673. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12674. //Check Charging Profile Count
  12675. tmpProfileQuantity = 0;
  12676. while(fscanf(fp, "%s", dataLine) != EOF)
  12677. {
  12678. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12679. {
  12680. profileQuantity += 1;
  12681. tmpProfileQuantity += 1;
  12682. }
  12683. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12684. }
  12685. fclose(fp);
  12686. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12687. }
  12688. //Check TxDefaultProfile_%d.json
  12689. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12690. {
  12691. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12692. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12693. if((access(fnametemp,F_OK))!=-1)
  12694. {
  12695. fp = fopen(fnametemp, "r");
  12696. //Check Charging Profile Count
  12697. tmpProfileQuantity = 0;
  12698. while(fscanf(fp, "%s", dataLine) != EOF)
  12699. {
  12700. //DEBUG_INFO("word=%s\n",word);
  12701. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12702. {
  12703. profileQuantity += 1;
  12704. tmpProfileQuantity += 1;
  12705. }
  12706. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12707. }
  12708. fclose(fp);
  12709. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12710. }
  12711. }
  12712. //Check TxProfile_%d.json
  12713. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12714. {
  12715. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12716. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12717. if((access(fnametemp,F_OK))!=-1)
  12718. {
  12719. fp = fopen(fnametemp, "r");
  12720. //Check Charging Profile Count
  12721. tmpProfileQuantity = 0;
  12722. while(fscanf(fp, "%s", dataLine) != EOF)
  12723. {
  12724. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12725. {
  12726. profileQuantity += 1;
  12727. tmpProfileQuantity += 1;
  12728. }
  12729. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12730. }
  12731. fclose(fp);
  12732. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12733. }
  12734. }
  12735. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12736. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12737. // To check total Profile quantity
  12738. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12739. {
  12740. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12741. {
  12742. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12743. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12744. goto end;
  12745. }
  12746. }
  12747. else
  12748. {
  12749. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12750. {
  12751. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12752. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12753. goto end;
  12754. }
  12755. }
  12756. }
  12757. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12758. //**********************************Write to File********************************************************/
  12759. {
  12760. FILE *infile;
  12761. FILE *outfile;
  12762. char dataLine[4096]={0};
  12763. char filename[128]={0};
  12764. int chkChar=0;
  12765. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12766. {
  12767. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12768. {
  12769. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12770. }
  12771. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12772. {
  12773. if(SetProfileReq.ConnectorId==0)
  12774. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12775. else
  12776. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12777. }
  12778. else
  12779. {
  12780. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12781. }
  12782. infile = fopen (filename, "r");
  12783. outfile = fopen (tempfile, "w");
  12784. chkChar = fgetc(infile);
  12785. rewind(infile);
  12786. if(chkChar == EOF)
  12787. {
  12788. // Profile is empty
  12789. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12790. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12791. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12792. fclose(infile);
  12793. fclose(outfile);
  12794. sprintf(rmFileCmd,"rm -f %s",filename);
  12795. system(rmFileCmd);
  12796. rename(tempfile, filename);
  12797. }
  12798. else
  12799. {
  12800. // Profile is not empty
  12801. int ChargingProfileAdded = FALSE;
  12802. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12803. {
  12804. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12805. json_object *tmpChargingProfile;
  12806. tmpChargingProfile = json_tokener_parse(dataLine);
  12807. if(!is_error(SetChargingProfile))
  12808. {
  12809. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12810. {
  12811. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12812. {
  12813. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12814. }
  12815. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12816. {
  12817. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12818. }
  12819. }
  12820. }
  12821. json_object_put(tmpChargingProfile);
  12822. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12823. {
  12824. if(ChargingProfileAdded == FALSE)
  12825. {
  12826. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12827. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12828. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12829. ChargingProfileAdded = TRUE;
  12830. }
  12831. }
  12832. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12833. {
  12834. if(ChargingProfileAdded == FALSE)
  12835. {
  12836. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12837. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12838. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12839. ChargingProfileAdded = TRUE;
  12840. }
  12841. }
  12842. else
  12843. {
  12844. fprintf(outfile,"%s\n",dataLine);
  12845. if(ChargingProfileAdded == FALSE)
  12846. {
  12847. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12848. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12849. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12850. ChargingProfileAdded = TRUE;
  12851. }
  12852. }
  12853. } // end of while loop
  12854. fclose(infile);
  12855. fclose(outfile);
  12856. sprintf(rmFileCmd,"rm -f %s",filename);
  12857. system(rmFileCmd);
  12858. rename(tempfile, filename);
  12859. }
  12860. }
  12861. sleep(1);
  12862. result = TRUE;
  12863. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12864. }
  12865. end:
  12866. json_object_put(SetChargingProfile);
  12867. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12868. {
  12869. if(SetProfileReq.ConnectorId == 0)
  12870. {
  12871. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12872. {
  12873. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12874. }
  12875. }
  12876. else
  12877. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12878. }
  12879. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12880. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12881. return result;
  12882. }
  12883. int handleTriggerMessageRequest(char *uuid, char *payload)
  12884. {
  12885. mtrace();
  12886. int result = FAIL;
  12887. int connectorIdIsNULL = FALSE;
  12888. int connectorIdInt =0;
  12889. char sstr[40]={0},sstrtemp[100]={ 0 };
  12890. char requestedMessagestr[40]={0};
  12891. char comfirmstr[20]={0};
  12892. int c = 0;
  12893. char *loc;
  12894. DEBUG_INFO("handleTriggerMessageRequest\n");
  12895. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12896. strcpy(sstrtemp, stringtrimspace(payload));
  12897. c = 0;
  12898. loc = strstr(sstrtemp, "requestedMessage");
  12899. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12900. {
  12901. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12902. c++;
  12903. }
  12904. sstr[c] = '\0';
  12905. strcpy(requestedMessagestr, sstr);
  12906. c = 0;
  12907. loc = strstr(sstrtemp, "connectorId");
  12908. if(loc == NULL)
  12909. {
  12910. connectorIdIsNULL = TRUE;
  12911. }
  12912. else
  12913. {
  12914. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12915. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12916. {
  12917. sstr[c] = loc[strlen("connectorId")+2+c];
  12918. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12919. c++;
  12920. }
  12921. sstr[c] = '\0';
  12922. connectorIdInt = atoi(sstr);
  12923. }
  12924. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12925. {
  12926. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12927. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12928. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12929. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12930. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12931. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12932. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12933. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12934. {
  12935. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12936. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12937. return TRUE;
  12938. }
  12939. else
  12940. {
  12941. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12942. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12943. }
  12944. }
  12945. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12946. {
  12947. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12948. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12949. return TRUE;
  12950. }
  12951. //==========================
  12952. // Trigger message
  12953. //==========================
  12954. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12955. {
  12956. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12957. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12958. {
  12959. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12960. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12961. }
  12962. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12963. }
  12964. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12965. {
  12966. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12967. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12968. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12969. }
  12970. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12971. {
  12972. //sendBootNotificationRequest();
  12973. server_sign = FALSE;
  12974. }
  12975. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12976. {
  12977. refreshStartTimer(&clientTime.Heartbeat);
  12978. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12979. }
  12980. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12981. {
  12982. if(connectorIdIsNULL == FALSE)
  12983. {
  12984. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12985. {
  12986. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12987. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12988. }
  12989. }
  12990. else
  12991. {
  12992. for(int idx=0;idx< gunTotalNumber;idx++)
  12993. {
  12994. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12995. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12996. }
  12997. }
  12998. }
  12999. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13000. {
  13001. if(connectorIdIsNULL == FALSE)
  13002. {
  13003. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13004. {
  13005. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13006. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  13007. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13008. }
  13009. }
  13010. else
  13011. {
  13012. for(int idx=0;idx< gunTotalNumber;idx++)
  13013. {
  13014. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  13015. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13016. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13017. }
  13018. }
  13019. }
  13020. return result;
  13021. }
  13022. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13023. {
  13024. mtrace();
  13025. int result = FAIL;
  13026. int connectorIdInt =0;
  13027. char comfirmstr[20]={0};
  13028. int tempIndex = 0;
  13029. json_object *UnlockConnector;
  13030. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13031. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13032. UnlockConnector = json_tokener_parse(payload);
  13033. if(!is_error(UnlockConnector))
  13034. {
  13035. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13036. {
  13037. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13038. }
  13039. }
  13040. json_object_put(UnlockConnector);
  13041. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13042. if(gunTotalNumber == 0)
  13043. {
  13044. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13045. goto end;
  13046. }
  13047. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13048. {
  13049. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13050. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13051. goto end;
  13052. }
  13053. else
  13054. {
  13055. //check Transaction active
  13056. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13057. {
  13058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13059. {
  13060. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13061. }
  13062. else
  13063. {
  13064. tempIndex = connectorIdInt -1;
  13065. }
  13066. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13067. {
  13068. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13069. {
  13070. //stop Transaction
  13071. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13072. }
  13073. }
  13074. }
  13075. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13076. {
  13077. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13078. {
  13079. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13080. }
  13081. else
  13082. {
  13083. tempIndex = connectorIdInt -1;
  13084. }
  13085. for (int index = 0; index < CCS_QUANTITY; index++)
  13086. {
  13087. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13088. {
  13089. //stop Transaction
  13090. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13091. }
  13092. }
  13093. }
  13094. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13095. {
  13096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13097. {
  13098. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13099. }
  13100. else
  13101. {
  13102. tempIndex = connectorIdInt -1;
  13103. }
  13104. for (int index = 0; index < GB_QUANTITY; index++)
  13105. {
  13106. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13107. {
  13108. //stop Transaction
  13109. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13110. }
  13111. }
  13112. }
  13113. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13114. {
  13115. tempIndex = connectorIdInt -1;
  13116. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13117. {
  13118. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13119. {
  13120. //stop Transaction
  13121. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13122. }
  13123. }
  13124. }
  13125. else
  13126. {
  13127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13128. {
  13129. tempIndex = 2;
  13130. }
  13131. else
  13132. {
  13133. tempIndex = connectorIdInt-1;
  13134. }
  13135. for (int index = 0; index < AC_QUANTITY; index++)
  13136. {
  13137. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13138. {
  13139. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13140. }
  13141. }
  13142. }
  13143. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13144. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  13145. result = TRUE;
  13146. return result;
  13147. }
  13148. end:
  13149. //json_object_put(obj); --- remove temporally
  13150. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13151. return result;
  13152. }
  13153. static char UpdateFirmwarepayloadData[300]={0};
  13154. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13155. {
  13156. mtrace();
  13157. int result = FAIL;
  13158. pthread_t t;
  13159. sendUpdateFirmwareConfirmation(uuid);
  13160. memset(UpdateFirmwarepayloadData, 0, 300);
  13161. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13162. if(!interLock.isUpdateFirmwareGoing)
  13163. {
  13164. interLock.isUpdateFirmwareGoing = 1;
  13165. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13166. sleep(1);
  13167. }
  13168. else
  13169. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13170. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  13171. return result;
  13172. }
  13173. void *UpdateFirmwareProcess(void *data)
  13174. {
  13175. pthread_detach(pthread_self());
  13176. mtrace();
  13177. int retriesInt =0, retryIntervalInt=0;
  13178. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  13179. int port=0;
  13180. char locationstr[512]={0}, retrieveDatestr[36]={0};
  13181. int isSuccess = 0;
  13182. char ftpbuf[512];
  13183. char temp[100];
  13184. char * pch;
  13185. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13186. json_object *UpdateFirmware;
  13187. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13188. if(!is_error(UpdateFirmware))
  13189. {
  13190. // Required data
  13191. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13192. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13193. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13194. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13195. // Optional data
  13196. if(json_object_object_get(UpdateFirmware, "retries"))
  13197. {
  13198. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13199. }
  13200. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13201. {
  13202. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13203. }
  13204. }
  13205. json_object_put(UpdateFirmware);
  13206. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13207. memset(path, 0, ARRAY_SIZE(path));
  13208. // Wait retrieveData
  13209. if(strlen(retrieveDatestr) > 10)
  13210. {
  13211. do
  13212. {
  13213. sleep(1);
  13214. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13215. }
  13216. // Ready to download
  13217. system("rm -f /mnt/*");
  13218. if(strncmp(locationstr,"http", 4) == 0)
  13219. {
  13220. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13221. sprintf(ftppath,"/%s", path);
  13222. DEBUG_INFO("locationstr: %s\n", locationstr);
  13223. DEBUG_INFO("protocol: %s\n",protocol);
  13224. DEBUG_INFO("host: %s\n",host);
  13225. DEBUG_INFO("path: %s\n",path);
  13226. DEBUG_INFO("ftppath: %s\n",ftppath);
  13227. int ftppathlen=strlen(ftppath);
  13228. int i=1;
  13229. char filenametemp[50];
  13230. while(i < ftppathlen)
  13231. {
  13232. int len=ftppathlen-i;
  13233. if(ftppath[len]== 47) // '/' ascll code: 47
  13234. {
  13235. DEBUG_INFO("compare '/' all right\n");
  13236. break;
  13237. }
  13238. i=i+1;
  13239. }
  13240. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13241. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13242. filenametemp[i+1] = 0;
  13243. do
  13244. {
  13245. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13246. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13247. sleep(1);
  13248. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13249. if(!isSuccess)
  13250. {
  13251. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13252. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13253. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13254. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13255. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13256. }
  13257. else
  13258. {
  13259. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13260. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13261. }
  13262. retriesInt--;
  13263. }while((isSuccess == 0)&&(retriesInt >= 0));
  13264. }
  13265. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13266. {
  13267. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13268. memset(temp, 0, ARRAY_SIZE(temp));
  13269. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13270. strcpy(ftpbuf, locationstr);
  13271. int ftppathlen=strlen(ftpbuf);
  13272. int i=1;
  13273. char filenametemp[50];
  13274. while(i < ftppathlen)
  13275. {
  13276. int len=ftppathlen-i;
  13277. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13278. {
  13279. DEBUG_INFO(" compare '/' all right\n");
  13280. break;
  13281. }
  13282. i=i+1;
  13283. }
  13284. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13285. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13286. filenametemp[i+1] = 0;
  13287. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13288. pch=strchr(temp,'@');
  13289. if(pch==NULL)
  13290. {
  13291. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13292. protocol, host, &port, path);
  13293. strcpy(user,"anonymous");
  13294. strcpy(password,"");
  13295. }
  13296. else
  13297. {
  13298. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13299. protocol, user, host, &port, path);
  13300. }
  13301. sscanf(host,"%[^/]%s",host1, path1);
  13302. sprintf(ftppath,"%s:/%s", host,path);
  13303. if(port == 0)
  13304. {
  13305. port = 21;
  13306. }
  13307. do
  13308. {
  13309. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13310. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13311. sleep(1);
  13312. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13313. if(!isSuccess)
  13314. {
  13315. //BulldogUtil.sleepMs(interval*1000);
  13316. DEBUG_INFO("Update firmware request and download file fail.\n");
  13317. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13318. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13319. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13320. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13321. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13322. }
  13323. else
  13324. {
  13325. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13326. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13327. }
  13328. retriesInt--;
  13329. }while((!isSuccess)&&(retriesInt >= 0));
  13330. }
  13331. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13332. {
  13333. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13334. memset(temp, 0, ARRAY_SIZE(temp));
  13335. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13336. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13337. int ftppathlen=strlen(ftpbuf);
  13338. int i=1;
  13339. char filenametemp[50];
  13340. while(i < ftppathlen)
  13341. {
  13342. int len=ftppathlen-i;
  13343. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13344. {
  13345. DEBUG_INFO(" compare '/' all right\n");
  13346. break;
  13347. }
  13348. i=i+1;
  13349. }
  13350. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13351. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13352. filenametemp[i+1] = 0;
  13353. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13354. pch=strchr(temp,'@');
  13355. if(pch==NULL)
  13356. {
  13357. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13358. protocol, host, &port, path);
  13359. strcpy(user,"anonymous");
  13360. strcpy(password,"");
  13361. }
  13362. else
  13363. {
  13364. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13365. protocol, user, password, host, &port, path);
  13366. }
  13367. sscanf(host,"%[^/]%s",host1, path1);
  13368. sprintf(ftppath,"%s", path1);
  13369. //DEBUG_INFO("protocol =%s\n",protocol);
  13370. //DEBUG_INFO("user =%s\n",user);
  13371. //DEBUG_INFO("password =%s\n",password);
  13372. //DEBUG_INFO("host1 =%s\n",host1);
  13373. //DEBUG_INFO("port =%d\n",port);
  13374. //DEBUG_INFO("path1 =%s\n",path1);
  13375. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13376. //ftpFile(host, user, password, port, ftppath, fname);
  13377. //download firmware pthred
  13378. if(port == 0)
  13379. {
  13380. port = 21;
  13381. }
  13382. do
  13383. {
  13384. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13385. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13386. sleep(1);
  13387. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13388. if(!isSuccess)
  13389. {
  13390. //BulldogUtil.sleepMs(interval*1000);
  13391. DEBUG_INFO("Update firmware request and download file fail.\n");
  13392. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13393. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13394. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13395. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13396. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13397. }
  13398. else
  13399. {
  13400. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13401. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13402. }
  13403. retriesInt--;
  13404. }while((!isSuccess)&&(retriesInt >= 0));
  13405. }
  13406. else
  13407. {
  13408. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13409. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13410. sleep(1);
  13411. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13412. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13413. }
  13414. // OCPPPH only, must announce CSU upgrade firmware
  13415. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13416. interLock.isUpdateFirmwareGoing = 0;
  13417. pthread_exit(NULL);
  13418. }
  13419. int handleCertificateSignedRequest(char *uuid, char *payload)
  13420. {
  13421. mtrace();
  13422. int result = PASS;
  13423. json_object *CertificateSigned;
  13424. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13425. CertificateSigned = json_tokener_parse(payload);
  13426. if(!is_error(CertificateSigned))
  13427. {
  13428. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13429. }
  13430. json_object_put(CertificateSigned);
  13431. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  13432. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  13433. fclose(fp);
  13434. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13435. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  13436. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  13437. sendCertificateSignedConfirmation(uuid);
  13438. return result;
  13439. }
  13440. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13441. {
  13442. mtrace();
  13443. int result = PASS;
  13444. json_object *DeleteCertificate;
  13445. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13446. DeleteCertificate = json_tokener_parse(payload);
  13447. if(!is_error(DeleteCertificate))
  13448. {
  13449. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13450. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13451. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13452. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13453. }
  13454. json_object_put(DeleteCertificate);
  13455. /*
  13456. * TODO: Delete certificateSigned process
  13457. */
  13458. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  13459. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  13460. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  13461. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  13462. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  13463. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  13464. sendDeleteCertificateConfirmation(uuid);
  13465. return result;
  13466. }
  13467. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13468. {
  13469. mtrace();
  13470. int result = PASS;
  13471. json_object *ExtendedTriggerMessage;
  13472. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13473. ExtendedTriggerMessage = json_tokener_parse(payload);
  13474. if(!is_error(ExtendedTriggerMessage))
  13475. {
  13476. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13477. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13478. {
  13479. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13480. }
  13481. else
  13482. {
  13483. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13484. }
  13485. }
  13486. json_object_put(ExtendedTriggerMessage);
  13487. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13488. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13489. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13490. {
  13491. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13492. }
  13493. else
  13494. {
  13495. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13496. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13497. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13498. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13499. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13500. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13501. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13502. {
  13503. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13504. }
  13505. else
  13506. {
  13507. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13508. }
  13509. }
  13510. sendExtendedTriggerMessageConfirmation(uuid);
  13511. //==========================
  13512. // Trigger message
  13513. //==========================
  13514. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13515. {
  13516. //sendBootNotificationRequest();
  13517. server_sign = FALSE;
  13518. }
  13519. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13520. {
  13521. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13522. }
  13523. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13524. {
  13525. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13526. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13527. {
  13528. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13529. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13530. }
  13531. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13532. }
  13533. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13534. {
  13535. refreshStartTimer(&clientTime.Heartbeat);
  13536. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13537. }
  13538. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13539. {
  13540. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13541. {
  13542. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13543. }
  13544. else
  13545. {
  13546. for(int idx=0;idx< gunTotalNumber;idx++)
  13547. {
  13548. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13549. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13550. }
  13551. }
  13552. }
  13553. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13554. {
  13555. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13556. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13557. {
  13558. 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\" &");
  13559. }
  13560. }
  13561. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13562. {
  13563. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13564. {
  13565. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13566. }
  13567. else
  13568. {
  13569. for(int idx=0;idx< gunTotalNumber;idx++)
  13570. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13571. }
  13572. }
  13573. return result;
  13574. }
  13575. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13576. {
  13577. mtrace();
  13578. int result = PASS;
  13579. json_object *GetInstalledCertificateIds;
  13580. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13581. GetInstalledCertificateIds = json_tokener_parse(payload);
  13582. if(!is_error(GetInstalledCertificateIds))
  13583. {
  13584. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13585. }
  13586. json_object_put(GetInstalledCertificateIds);
  13587. /*
  13588. * TODO: Return installed certificate process
  13589. */
  13590. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13591. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13592. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13593. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13594. sendGetInstalledCertificateIdsConfirmation(uuid);
  13595. return result;
  13596. }
  13597. int handleGetLogRequest(char *uuid, char *payload)
  13598. {
  13599. mtrace();
  13600. int result = PASS;
  13601. json_object *GetLog;
  13602. DEBUG_INFO("handleGetLogRequest...\n");
  13603. GetLog = json_tokener_parse(payload);
  13604. if(!is_error(GetLog))
  13605. {
  13606. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13607. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13608. if(json_object_object_get(GetLog, "retries") != NULL)
  13609. {
  13610. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13611. }
  13612. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13613. {
  13614. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13615. }
  13616. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13617. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13618. {
  13619. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13620. }
  13621. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13622. {
  13623. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13624. }
  13625. }
  13626. json_object_put(GetLog);
  13627. /*
  13628. * TODO: Upload log process
  13629. */
  13630. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13631. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13632. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13633. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13634. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13635. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13636. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13637. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13638. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13639. sendGetLogConfirmation(uuid);
  13640. return result;
  13641. }
  13642. int handleInstallCertificateRequest(char *uuid, char *payload)
  13643. {
  13644. mtrace();
  13645. int result = PASS;
  13646. json_object *InstallCertificate;
  13647. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13648. InstallCertificate = json_tokener_parse(payload);
  13649. if(!is_error(InstallCertificate))
  13650. {
  13651. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13652. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13653. /*
  13654. * TODO: Install certificate process
  13655. */
  13656. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13657. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13658. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13659. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13660. sendInstallCertificateConfirmation(uuid);
  13661. }
  13662. json_object_put(InstallCertificate);
  13663. return result;
  13664. }
  13665. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13666. {
  13667. mtrace();
  13668. int result = PASS;
  13669. json_object *SignedUpdateFirmware;
  13670. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13671. SignedUpdateFirmware = json_tokener_parse(payload);
  13672. if(!is_error(SignedUpdateFirmware))
  13673. {
  13674. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13675. {
  13676. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13677. }
  13678. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13679. {
  13680. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13681. }
  13682. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13683. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13684. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13685. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13686. {
  13687. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13688. }
  13689. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13690. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13691. }
  13692. json_object_put(SignedUpdateFirmware);
  13693. /*
  13694. * TODO: Upgrade firmware process
  13695. */
  13696. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13697. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13698. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13699. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13700. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13701. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13702. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13703. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13704. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13705. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13706. sendInstallCertificateConfirmation(uuid);
  13707. return result;
  13708. }
  13709. int handleUnknownRequest(char *uuid, char *payload)
  13710. {
  13711. mtrace();
  13712. int result = PASS;
  13713. DEBUG_INFO("handleUnknownRequest...\n");
  13714. sendUnknownConfirmation(uuid);
  13715. result = PASS;
  13716. return result;
  13717. }
  13718. //==========================================
  13719. // Handle server response routine
  13720. //==========================================
  13721. void handleAuthorizeResponse(char *payload, int gun_index)
  13722. {
  13723. mtrace();
  13724. char expiryDatestr[36]={0};
  13725. char parentIdTagstr[21]={0};
  13726. char statusstr[20]={0};
  13727. int expiryDateISNULL=FALSE;
  13728. int parentIdTagISNULL=FALSE;
  13729. DEBUG_INFO("handleAuthorizeResponse...\n");
  13730. json_object *Authorize;
  13731. Authorize = json_tokener_parse(payload);
  13732. if(!is_error(Authorize))
  13733. {
  13734. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13735. {
  13736. // Required data
  13737. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13738. // Optional data
  13739. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13740. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13741. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13742. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13743. }
  13744. }
  13745. json_object_put(Authorize);
  13746. if(expiryDateISNULL == FALSE)
  13747. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13748. if(parentIdTagISNULL == FALSE)
  13749. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13750. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13751. //Update idTag information to authorization cache if supproted
  13752. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13753. {
  13754. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13755. }
  13756. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13757. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13758. authorizeRetryTimes = 0;
  13759. }
  13760. void handleBootNotificationResponse(char *payload, int gun_index)
  13761. {
  13762. mtrace();
  13763. char statusStr[12]={0};
  13764. char currentTimeStr[30]={0};
  13765. int intervalInt = 0;
  13766. DEBUG_INFO("handleBootNotificationResponse...\n");
  13767. json_object *BootNotification;
  13768. BootNotification = json_tokener_parse(payload);
  13769. if(!is_error(BootNotification))
  13770. {
  13771. // Required data
  13772. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13773. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13774. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13775. }
  13776. json_object_put(BootNotification);
  13777. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13778. BootNotificationInterval = intervalInt;
  13779. //write back to ShmOCPP16DataPH->BootNotification
  13780. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13781. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13782. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13783. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13784. {
  13785. BootNotificationInterval = 0;
  13786. if((intervalInt == 0) || (intervalInt >= 10))
  13787. {
  13788. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13789. HeartBeatWaitTime = intervalInt;
  13790. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13791. }
  13792. server_sign = TRUE;
  13793. server_pending =FALSE;
  13794. }
  13795. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13796. {
  13797. server_pending = TRUE;
  13798. }
  13799. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13800. srand(time(NULL));
  13801. refreshStartTimer(&clientTime.Heartbeat);
  13802. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13803. SetOcppConnStatus(TRUE);
  13804. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13805. }
  13806. void handleDataTransferResponse(char *payload, int gun_index)
  13807. {
  13808. json_object *DataTransfer = json_tokener_parse(payload);
  13809. if(!is_error(DataTransfer))
  13810. {
  13811. // Required data
  13812. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13813. // Optional data
  13814. if(json_object_object_get(DataTransfer, "data") != NULL)
  13815. {
  13816. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13817. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13818. if(!is_error(Data))
  13819. {
  13820. if(json_object_object_get(Data, "msgId") != NULL)
  13821. {
  13822. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13823. {
  13824. 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")));
  13825. }
  13826. }
  13827. }
  13828. json_object_put(Data);
  13829. }
  13830. }
  13831. json_object_put(DataTransfer);
  13832. }
  13833. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13834. {
  13835. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13836. //struct json_object *obj;
  13837. // obj = json_tokener_parse(payload);
  13838. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13839. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13840. //No fields are defined.
  13841. }
  13842. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13843. {
  13844. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13845. //struct json_object *obj;
  13846. // obj = json_tokener_parse(payload);
  13847. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13848. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13849. //No fields are defined.
  13850. }
  13851. void handleHeartbeatResponse(char *payload, int gun_index)
  13852. {
  13853. mtrace();
  13854. DEBUG_INFO("handleHeartbeatResponse...\n");
  13855. json_object *Heartbeat;
  13856. Heartbeat = json_tokener_parse(payload);
  13857. if(!is_error(Heartbeat))
  13858. {
  13859. // Required data
  13860. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13861. }
  13862. json_object_put(Heartbeat);
  13863. if(FirstHeartBeat == 0)
  13864. {
  13865. FirstHeartBeat = 1;
  13866. DEBUG_INFO("FirstHeartBeat \n");
  13867. }
  13868. HeartBeatWithNOResponse = 0;
  13869. refreshStartTimer(&clientTime.Heartbeat);
  13870. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13871. }
  13872. void handleMeterValuesResponse(char *payload, int gun_index)
  13873. {
  13874. mtrace();
  13875. DEBUG_INFO("handleMeterValuesResponse...\n");
  13876. isQueueSendable = 1;
  13877. }
  13878. void handleStartTransactionResponse(char *payload, int gun_index)
  13879. {
  13880. mtrace();
  13881. //int transactionIdInt = 0;
  13882. FILE *outfile;
  13883. char data[100]={0};
  13884. DEBUG_INFO("handleStartTransactionResponse...\n");
  13885. json_object *StartTransaction;
  13886. StartTransaction = json_tokener_parse(payload);
  13887. if(!is_error(StartTransaction))
  13888. {
  13889. // Required data
  13890. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13891. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13892. // Optional data
  13893. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13894. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13895. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13896. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13897. }
  13898. json_object_put(StartTransaction);
  13899. isQueueSendable = 1;
  13900. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13901. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13902. //-----------Start : write to the Queue TransactionId file -----------------//
  13903. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13904. {}
  13905. else
  13906. {
  13907. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13908. if(log == NULL)
  13909. {
  13910. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13911. return ;
  13912. }
  13913. else
  13914. {
  13915. fclose(log);
  13916. }
  13917. }
  13918. // open file for writing
  13919. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13920. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13921. {
  13922. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13923. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13924. fputs(data, outfile);
  13925. fclose (outfile);
  13926. }
  13927. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13928. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13929. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13930. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13931. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13932. }
  13933. void handleStatusNotificationResponse(char *payload, int gun_index)
  13934. {
  13935. mtrace();
  13936. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13937. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13938. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13939. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13940. }
  13941. void handleStopTransactionnResponse(char *payload, int gun_index)
  13942. {
  13943. mtrace();
  13944. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13945. json_object *StopTransaction;
  13946. StopTransaction = json_tokener_parse(payload);
  13947. if(!is_error(StopTransaction))
  13948. {
  13949. // Optional data
  13950. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13951. {
  13952. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13953. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13954. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13955. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13956. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13957. }
  13958. }
  13959. json_object_put(StopTransaction);
  13960. isQueueSendable = 1;
  13961. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13962. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13963. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13964. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13965. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13966. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13967. }
  13968. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13969. {
  13970. mtrace();
  13971. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13972. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13973. }
  13974. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13975. {
  13976. mtrace();
  13977. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13978. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13979. }
  13980. void handleSignCertificateResponse(char *payload, int gun_index)
  13981. {
  13982. mtrace();
  13983. DEBUG_INFO("handleSignCertificateResponse...\n");
  13984. json_object *SignCertificate;
  13985. SignCertificate = json_tokener_parse(payload);
  13986. if(!is_error(SignCertificate))
  13987. {
  13988. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13989. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13990. }
  13991. json_object_put(SignCertificate);
  13992. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13993. }
  13994. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13995. {
  13996. mtrace();
  13997. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13998. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13999. }
  14000. //==========================================
  14001. // Handle Error routine
  14002. //==========================================
  14003. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14004. {
  14005. mtrace();
  14006. #ifdef SystemLogMessage
  14007. DEBUG_INFO("errorCode: %s\n", errorCode);
  14008. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14009. DEBUG_INFO("errorDetails: %s\n", payload);
  14010. #endif
  14011. }
  14012. //===============================================
  14013. // Common routine
  14014. //===============================================
  14015. int initialConfigurationTable(void)
  14016. {
  14017. //clock_t start_t, end_t, total_t;
  14018. FILE *fp;
  14019. FILE *outfile;
  14020. char str[512]={0};
  14021. char sstr[256]={0};
  14022. int c = 0;
  14023. char *loc;
  14024. int confVersion = 18;
  14025. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14026. //start_t = clock();
  14027. //printf("Starting of the program, start_t = %ld\n", start_t);
  14028. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14029. // Check configuration file size is correct
  14030. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  14031. {
  14032. struct stat st;
  14033. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  14034. if(st.st_size < 3100)
  14035. {
  14036. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  14037. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14038. }
  14039. }
  14040. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  14041. {
  14042. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14043. if(outfile == NULL)
  14044. {
  14045. DEBUG_INFO("Error opening file\n");
  14046. return FALSE;
  14047. }
  14048. /*Core Profile*/
  14049. //AllowOfflineTxForUnknownId
  14050. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14054. //AuthorizationCacheEnabled
  14055. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14059. //AuthorizeRemoteTxRequests
  14060. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14061. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14064. //BlinkRepeat
  14065. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14067. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14069. //ClockAlignedDataInterval
  14070. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14071. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14074. //ConnectionTimeOut
  14075. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14076. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14079. //GetConfigurationMaxKeys
  14080. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14081. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14082. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14084. // HeartbeatInterval
  14085. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14089. // LightIntensity
  14090. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14094. // LocalAuthorizeOffline
  14095. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14096. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14099. // LocalPreAuthorize
  14100. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14102. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14104. // MaxEnergyOnInvalidId
  14105. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14106. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14109. // MeterValuesAlignedData
  14110. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14111. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14112. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14113. 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" );
  14114. else
  14115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14117. // MeterValuesAlignedDataMaxLength
  14118. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14122. else
  14123. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14125. // MeterValuesSampledData
  14126. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14127. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14128. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14129. 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" );
  14130. else
  14131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14133. // MeterValuesSampledDataMaxLength
  14134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14137. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14138. else
  14139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14141. // MeterValueSampleInterval
  14142. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14143. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14144. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14146. // MinimumStatusDuration
  14147. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14148. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14150. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14152. // NumberOfConnectors
  14153. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14155. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14156. {
  14157. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14158. }
  14159. else
  14160. {
  14161. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14162. }
  14163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14164. // ResetRetries
  14165. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14166. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14169. // ConnectorPhaseRotation
  14170. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14172. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14174. // ConnectorPhaseRotationMaxLength
  14175. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14179. // StopTransactionOnEVSideDisconnect
  14180. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14184. // StopTransactionOnInvalidId
  14185. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14187. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14189. // StopTxnAlignedData
  14190. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14194. // StopTxnAlignedDataMaxLength
  14195. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14197. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14199. // StopTxnSampledData
  14200. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14201. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14202. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14204. else
  14205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14207. // StopTxnSampledDataMaxLength
  14208. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14209. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14210. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14211. {
  14212. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14213. }
  14214. else
  14215. {
  14216. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14217. }
  14218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14219. // SupportedFeatureProfiles
  14220. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14221. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14222. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14224. // SupportedFeatureProfilesMaxLength
  14225. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14229. // TransactionMessageAttempts
  14230. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14231. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14232. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14233. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14235. // TransactionMessageRetryInterval
  14236. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14237. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14238. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14239. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14241. // UnlockConnectorOnEVSideDisconnect
  14242. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14243. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14244. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14246. // WebSocketPingInterval
  14247. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14248. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14249. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14251. // QueueOffLineMeterValues
  14252. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14253. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14254. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14256. // AuthorizationKey
  14257. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14258. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14259. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  14260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14261. // SecurityProfile
  14262. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14263. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14264. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14266. // DefaultPrice
  14267. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14268. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14271. // CustomDisplayCostAndPrice
  14272. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14273. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14274. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14276. // CustomIdleFeeAfterStop
  14277. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14278. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14279. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14281. // SystemUptimeSec
  14282. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14283. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14284. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14286. // FreeVend
  14287. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14288. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14289. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14291. // FreeVendIdtag
  14292. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14293. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14294. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14296. // OcppServer
  14297. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14298. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14299. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14301. // MaintainServer
  14302. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14303. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14304. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14306. // StatusNotificationPeriodically
  14307. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14308. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14309. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14311. // StatusNotificationInterval
  14312. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14313. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14314. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14316. // isEnableLocalPowerSharing
  14317. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14319. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14321. // PowerSharingServerIP
  14322. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14323. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14324. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14326. // EVCCID_PREFIX
  14327. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14328. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14329. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14331. // OffLineMaxChargingPower
  14332. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  14333. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  14334. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  14335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  14336. // Configuration Version
  14337. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14338. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14339. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14341. // Charging profile refresh interval
  14342. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  14343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  14344. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  14345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  14346. // Ocpp Software certificated version
  14347. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  14348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  14349. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  14350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  14351. //* Local Auth List Management Profile*/
  14352. #if 0
  14353. //For OCTT Test Case
  14354. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14355. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14357. #endif
  14358. #if 1
  14359. //LocalAuthListEnabled
  14360. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14361. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14364. #endif
  14365. //LocalAuthListMaxLength
  14366. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14367. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14370. //SendLocalListMaxLength
  14371. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14373. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  14374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14375. //ReserveConnectorZeroSupported
  14376. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14377. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14380. //* Smart Charging Profile */
  14381. //ChargeProfileMaxStackLevel
  14382. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14383. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14384. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14386. // ChargingScheduleAllowedChargingRateUnit
  14387. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14388. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14391. // ChargingScheduleMaxPeriods
  14392. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14393. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14394. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14396. // ConnectorSwitch3to1PhaseSupported
  14397. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14398. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14401. // MaxChargingProfilesInstalled
  14402. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14404. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14406. fclose(outfile);
  14407. }
  14408. else
  14409. {
  14410. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  14411. char keystr[60]={0};
  14412. char readonlystr[10]={0};
  14413. char valuestr[256]={0};
  14414. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  14415. if(fp == NULL) {
  14416. DEBUG_INFO("Error opening file");
  14417. return FALSE;
  14418. }
  14419. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14420. {
  14421. //DEBUG_INFO("Get Configuration \n");
  14422. if(strlen(str) > 0)
  14423. {
  14424. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14425. //*************************key*********************************/
  14426. if(strstr(str, "key") != NULL)
  14427. {
  14428. loc = strstr(str, "key");
  14429. c = 0;
  14430. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14431. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14432. {
  14433. sstr[c] = loc[strlen("key")+3+c];
  14434. c++;
  14435. }
  14436. sstr[c] = '\0';
  14437. strcpy(keystr,sstr);
  14438. }
  14439. //*************************readonly*********************************/
  14440. if(strstr(str, "readonly") != NULL)
  14441. {
  14442. loc = strstr(str, "readonly");
  14443. c = 0;
  14444. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14445. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14446. {
  14447. sstr[c] = loc[strlen("readonly")+2+c];
  14448. c++;
  14449. }
  14450. sstr[c] = '\0';
  14451. strcpy(readonlystr,sstr);
  14452. }
  14453. //*************************value*********************************/
  14454. if(strstr(str, "value") != NULL)
  14455. {
  14456. loc = strstr(str, "value");
  14457. c = 0;
  14458. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14459. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14460. {
  14461. sstr[c] = loc[strlen("value")+3+c];
  14462. c++;
  14463. }
  14464. sstr[c] = '\0';
  14465. strcpy(valuestr,sstr);
  14466. }
  14467. // DEBUG_INFO("keystr=%s\n",keystr);
  14468. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14469. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14470. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14471. {
  14472. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14473. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14474. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14475. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14476. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14477. }
  14478. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14479. {
  14480. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14481. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14482. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14483. }
  14484. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14485. {
  14486. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14487. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14488. }
  14489. if(strcmp(keystr, "BlinkRepeat") == 0)
  14490. {
  14491. //Charger.BlinkRepeat = Integer.parseInt(value);
  14492. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14493. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14494. }
  14495. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14496. {
  14497. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14498. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14499. }
  14500. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14501. {
  14502. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14503. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14504. }
  14505. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14506. {
  14507. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14508. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14509. }
  14510. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14511. {
  14512. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14513. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14514. HeartBeatWaitTime = atoi(valuestr);
  14515. }
  14516. if(strcmp(keystr, "LightIntensity") == 0)
  14517. {
  14518. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14519. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14520. }
  14521. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14522. {
  14523. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14524. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14525. }
  14526. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14527. {
  14528. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14529. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14530. }
  14531. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14532. {
  14533. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14534. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14535. }
  14536. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14537. {
  14538. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14539. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14540. }
  14541. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14542. {
  14543. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14544. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14545. }
  14546. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14547. {
  14548. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14549. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14550. }
  14551. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14552. {
  14553. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14554. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14555. }
  14556. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14557. {
  14558. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14559. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14560. }
  14561. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14562. {
  14563. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14564. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14565. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14566. }
  14567. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14568. {
  14569. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14570. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14571. }
  14572. if(strcmp(keystr, "ResetRetries") == 0)
  14573. {
  14574. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14575. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14576. }
  14577. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14578. {
  14579. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14580. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14581. }
  14582. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14583. {
  14584. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14585. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14586. }
  14587. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14588. {
  14589. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14590. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14591. }
  14592. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14593. {
  14594. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14595. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14596. }
  14597. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14598. {
  14599. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14600. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14601. }
  14602. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14603. {
  14604. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14605. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14606. }
  14607. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14608. {
  14609. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14610. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14611. }
  14612. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14613. {
  14614. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14615. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14616. }
  14617. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14618. {
  14619. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14620. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14621. }
  14622. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14623. {
  14624. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14625. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14626. }
  14627. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14628. {
  14629. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14630. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14631. TransactionMessageAttemptsValue = atoi(valuestr);
  14632. }
  14633. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14634. {
  14635. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14636. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14637. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14638. }
  14639. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14640. {
  14641. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14642. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14643. }
  14644. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14645. {
  14646. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14647. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14648. }
  14649. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14650. {
  14651. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14652. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14653. }
  14654. if(strcmp(keystr, "AuthorizationKey") == 0)
  14655. {
  14656. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14657. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14658. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14659. }
  14660. if(strcmp(keystr, "SecurityProfile") == 0)
  14661. {
  14662. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14663. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14664. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14665. }
  14666. if(strcmp(keystr, "DefaultPrice") == 0)
  14667. {
  14668. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14669. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14670. }
  14671. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14672. {
  14673. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14674. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14675. }
  14676. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14677. {
  14678. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14679. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14680. }
  14681. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14682. {
  14683. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14684. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14685. }
  14686. if(strcmp(keystr, "FreeVend") == 0)
  14687. {
  14688. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14689. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14690. }
  14691. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14692. {
  14693. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14694. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14695. }
  14696. if(strcmp(keystr, "OcppServer") == 0)
  14697. {
  14698. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14699. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14700. }
  14701. if(strcmp(keystr, "MaintainServer") == 0)
  14702. {
  14703. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14704. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14705. }
  14706. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14707. {
  14708. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14709. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14710. }
  14711. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14712. {
  14713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14714. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14715. }
  14716. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14717. {
  14718. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14719. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14720. }
  14721. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14722. {
  14723. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14724. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14725. }
  14726. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14727. {
  14728. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14729. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14730. }
  14731. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  14732. {
  14733. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  14735. }
  14736. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14737. {
  14738. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14739. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14740. }
  14741. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  14742. {
  14743. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14744. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  14745. }
  14746. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  14747. {
  14748. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14749. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  14750. }
  14751. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14752. {
  14753. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14754. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14755. }
  14756. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14757. {
  14758. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14759. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14760. }
  14761. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14762. {
  14763. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14764. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14765. }
  14766. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14767. {
  14768. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14769. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14770. }
  14771. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14772. {
  14773. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14774. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14775. }
  14776. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14777. {
  14778. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14779. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14780. }
  14781. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14782. {
  14783. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14784. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14785. }
  14786. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14787. {
  14788. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14789. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14790. }
  14791. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14792. {
  14793. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14794. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14795. }
  14796. }
  14797. }
  14798. fclose(fp);
  14799. }
  14800. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14801. {
  14802. return PASS;
  14803. }
  14804. else
  14805. {
  14806. return FAIL;
  14807. }
  14808. }
  14809. void StoreConfigurationTable(void)
  14810. {
  14811. FILE *outfile;
  14812. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14813. if(outfile == NULL)
  14814. {
  14815. DEBUG_INFO("Error opening file");
  14816. return ;
  14817. }
  14818. /*Core Profile*/
  14819. //AllowOfflineTxForUnknownId
  14820. /*
  14821. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14822. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14823. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14824. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14825. */
  14826. //DEBUG_INFO("data=%s\n",data);
  14827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14828. //AuthorizationCacheEnabled
  14829. /*
  14830. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14832. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14833. */
  14834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14835. //AuthorizeRemoteTxRequests
  14836. /*
  14837. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14838. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14839. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14840. */
  14841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14842. //BlinkRepeat
  14843. /*
  14844. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14846. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14847. */
  14848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14849. //ClockAlignedDataInterval
  14850. /*
  14851. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14852. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14853. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14854. */
  14855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14856. //ConnectionTimeOut
  14857. /*
  14858. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14860. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14861. */
  14862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14863. //GetConfigurationMaxKeys
  14864. /*
  14865. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14867. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14868. */
  14869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14870. // HeartbeatInterval
  14871. /*
  14872. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14873. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14874. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14875. */
  14876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14877. // LightIntensity
  14878. /*
  14879. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14880. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14881. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14882. */
  14883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14884. // LocalAuthorizeOffline
  14885. /*
  14886. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14888. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14889. */
  14890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14891. // LocalPreAuthorize
  14892. /*
  14893. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14894. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14895. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14896. */
  14897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14898. // MaxEnergyOnInvalidId
  14899. /*
  14900. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14901. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14902. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14903. */
  14904. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14906. // MeterValuesAlignedData
  14907. /*
  14908. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14909. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14911. */
  14912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14913. // MeterValuesAlignedDataMaxLength
  14914. /*
  14915. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14916. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14917. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14918. */
  14919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14920. // MeterValuesSampledData
  14921. /*
  14922. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14923. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14924. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14925. */
  14926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14927. // MeterValuesSampledDataMaxLength
  14928. /*
  14929. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14930. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14932. */
  14933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14934. // MeterValueSampleInterval
  14935. /*
  14936. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14937. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14939. */
  14940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14941. // MinimumStatusDuration
  14942. /*
  14943. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14944. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14946. */
  14947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14948. // NumberOfConnectors
  14949. /*
  14950. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14951. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14952. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14953. {
  14954. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14955. }
  14956. else
  14957. {
  14958. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14959. }
  14960. */
  14961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14962. // ResetRetries
  14963. /*
  14964. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14965. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14967. */
  14968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14969. // ConnectorPhaseRotation
  14970. /*
  14971. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14972. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14973. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14974. */
  14975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14976. // ConnectorPhaseRotationMaxLength
  14977. /*
  14978. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14979. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14981. */
  14982. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14983. // StopTransactionOnEVSideDisconnect
  14984. /*
  14985. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14987. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14988. */
  14989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14990. // StopTransactionOnInvalidId
  14991. /*
  14992. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14993. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14994. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14995. */
  14996. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14997. // StopTxnAlignedData
  14998. /*
  14999. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  15002. */
  15003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15004. // StopTxnAlignedDataMaxLength
  15005. /*
  15006. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15008. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15009. */
  15010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15011. // StopTxnSampledData
  15012. /*
  15013. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15014. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15015. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  15016. */
  15017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15018. // StopTxnSampledDataMaxLength
  15019. /*
  15020. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15022. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  15023. */
  15024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15025. // SupportedFeatureProfiles
  15026. /*
  15027. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15028. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15030. */
  15031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15032. // SupportedFeatureProfilesMaxLength
  15033. /*
  15034. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15037. */
  15038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15039. // TransactionMessageAttempts
  15040. /*
  15041. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15044. */
  15045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15046. // TransactionMessageRetryInterval
  15047. /*
  15048. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15050. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15051. */
  15052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15053. // UnlockConnectorOnEVSideDisconnect
  15054. /*
  15055. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15058. */
  15059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15060. // WebSocketPingInterval
  15061. /*
  15062. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15063. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15064. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15065. */
  15066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15067. // QueueOffLineMeterValues
  15068. /*
  15069. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15070. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15071. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15072. */
  15073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15074. // AuthorizationKey
  15075. /*
  15076. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15079. */
  15080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15081. // SecurityProfile
  15082. /*
  15083. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15084. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15085. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15086. */
  15087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15088. // DefaultPrice
  15089. /*
  15090. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15093. */
  15094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15095. // CustomDisplayCostAndPrice
  15096. /*
  15097. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15098. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15099. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15100. */
  15101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15102. // CustomIdleFeeAfterStop
  15103. /*
  15104. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15105. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15106. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15107. */
  15108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15109. // SystemUptimeSec
  15110. /*
  15111. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15113. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15114. */
  15115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15116. // FreeVend
  15117. /*
  15118. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15121. */
  15122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15123. // FreeVendIdtag
  15124. /*
  15125. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15127. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15128. */
  15129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15130. // OcppServer
  15131. /*
  15132. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15133. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15135. */
  15136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15137. // MaintainServer
  15138. /*
  15139. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15142. */
  15143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15144. // StatusNotificationPeriodically
  15145. /*
  15146. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15147. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15148. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15149. */
  15150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15151. // StatusNotificationInterval
  15152. /*
  15153. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15156. */
  15157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15158. // isEnableLocalPowerSharing
  15159. /*
  15160. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15163. */
  15164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15165. // PowerSharingServerIP
  15166. /*
  15167. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15170. */
  15171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15172. // EVCCID_PREFIX
  15173. /*
  15174. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15177. */
  15178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15179. // OffLineMaxChargingPower
  15180. /*
  15181. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  15184. */
  15185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15186. // ConfigurationVersion
  15187. /*
  15188. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15191. */
  15192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15193. // CharingProfileRefreshInterval
  15194. /*
  15195. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15197. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  15198. */
  15199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15200. // OcppSoftwareVersion
  15201. /*
  15202. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  15203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  15205. */
  15206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15207. //* Local Auth List Management Profile*/
  15208. //LocalAuthListEnabled
  15209. /*
  15210. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15213. */
  15214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15215. //LocalAuthListMaxLength
  15216. /*
  15217. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15220. */
  15221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15222. //SendLocalListMaxLength
  15223. /*
  15224. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15225. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15227. */
  15228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15229. //ReserveConnectorZeroSupported
  15230. /*
  15231. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15232. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15233. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15234. */
  15235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15236. //* Smart Charging Profile */
  15237. //ChargeProfileMaxStackLevel
  15238. /*
  15239. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15242. */
  15243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15244. // ChargingScheduleAllowedChargingRateUnit
  15245. /*
  15246. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15247. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15248. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15249. */
  15250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15251. // ChargingScheduleMaxPeriods
  15252. /*
  15253. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15254. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15256. */
  15257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15258. // ConnectorSwitch3to1PhaseSupported
  15259. /*
  15260. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15261. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15262. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15263. */
  15264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15265. // MaxChargingProfilesInstalled
  15266. /*
  15267. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15268. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15270. */
  15271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15272. fclose(outfile);
  15273. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15274. }
  15275. void getKeyValue(char *keyReq)
  15276. {
  15277. int isEmpty = FALSE;
  15278. int isKnowKey = FALSE;
  15279. DEBUG_INFO("keyReq = %s\n", keyReq);
  15280. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15281. isEmpty = TRUE;
  15282. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15283. {
  15284. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15285. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15286. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15287. {
  15288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15289. }
  15290. else
  15291. {
  15292. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15293. }
  15294. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15295. isKnowKey = TRUE;
  15296. }
  15297. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15298. {
  15299. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15300. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15301. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15302. {
  15303. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15304. }
  15305. else
  15306. {
  15307. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15308. }
  15309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15310. isKnowKey = TRUE;
  15311. }
  15312. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15313. {
  15314. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15315. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15316. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15317. {
  15318. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15319. }
  15320. else
  15321. {
  15322. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15323. }
  15324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15325. isKnowKey = TRUE;
  15326. }
  15327. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15328. {
  15329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15330. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15331. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15332. {
  15333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15334. }
  15335. else
  15336. {
  15337. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15338. }
  15339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15340. isKnowKey = TRUE;
  15341. }
  15342. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15343. {
  15344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15345. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15346. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15347. {
  15348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15349. }
  15350. else
  15351. {
  15352. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15353. }
  15354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15355. isKnowKey = TRUE;
  15356. }
  15357. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15358. {
  15359. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15361. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15362. {
  15363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15364. }
  15365. else
  15366. {
  15367. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15368. }
  15369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15370. isKnowKey = TRUE;
  15371. }
  15372. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15373. {
  15374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15376. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15377. {
  15378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15379. }
  15380. else
  15381. {
  15382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15383. }
  15384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15385. isKnowKey = TRUE;
  15386. }
  15387. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15388. {
  15389. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15391. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15392. {
  15393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15394. }
  15395. else
  15396. {
  15397. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15398. }
  15399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15400. isKnowKey = TRUE;
  15401. }
  15402. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15403. {
  15404. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15406. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15407. {
  15408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15409. }
  15410. else
  15411. {
  15412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15413. }
  15414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15415. isKnowKey = TRUE;
  15416. }
  15417. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15418. {
  15419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15421. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15422. {
  15423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15424. }
  15425. else
  15426. {
  15427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15428. }
  15429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15430. isKnowKey = TRUE;
  15431. }
  15432. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15433. {
  15434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15436. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15437. {
  15438. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15439. }
  15440. else
  15441. {
  15442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15443. }
  15444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15445. isKnowKey = TRUE;
  15446. }
  15447. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15448. {
  15449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15451. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15452. {
  15453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15454. }
  15455. else
  15456. {
  15457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15458. }
  15459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15460. isKnowKey = TRUE;
  15461. }
  15462. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15463. {
  15464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15466. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15467. {
  15468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15469. }
  15470. else
  15471. {
  15472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15473. }
  15474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15475. isKnowKey = TRUE;
  15476. }
  15477. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15478. {
  15479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15481. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15482. {
  15483. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15484. }
  15485. else
  15486. {
  15487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15488. }
  15489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15490. isKnowKey = TRUE;
  15491. }
  15492. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15493. {
  15494. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15496. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15497. {
  15498. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15499. }
  15500. else
  15501. {
  15502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15503. }
  15504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15505. isKnowKey = TRUE;
  15506. }
  15507. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15508. {
  15509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15511. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15512. {
  15513. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15514. }
  15515. else
  15516. {
  15517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15518. }
  15519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15520. isKnowKey = TRUE;
  15521. }
  15522. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15523. {
  15524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15526. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15527. {
  15528. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15529. }
  15530. else
  15531. {
  15532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15533. }
  15534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15535. isKnowKey = TRUE;
  15536. }
  15537. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15538. {
  15539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15541. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15542. {
  15543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15544. }
  15545. else
  15546. {
  15547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15548. }
  15549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  15550. isKnowKey = TRUE;
  15551. }
  15552. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15553. {
  15554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15556. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15557. {
  15558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15559. }
  15560. else
  15561. {
  15562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15563. }
  15564. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15566. isKnowKey = TRUE;
  15567. }
  15568. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15569. {
  15570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15572. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15573. {
  15574. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15575. }
  15576. else
  15577. {
  15578. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15579. }
  15580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15581. isKnowKey = TRUE;
  15582. }
  15583. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15584. {
  15585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15587. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15588. {
  15589. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15590. }
  15591. else
  15592. {
  15593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15594. }
  15595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15596. isKnowKey = TRUE;
  15597. }
  15598. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15599. {
  15600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15602. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15603. {
  15604. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15605. }
  15606. else
  15607. {
  15608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15609. }
  15610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15611. isKnowKey = TRUE;
  15612. }
  15613. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15614. {
  15615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15617. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15618. {
  15619. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15620. }
  15621. else
  15622. {
  15623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15624. }
  15625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15626. isKnowKey = TRUE;
  15627. }
  15628. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15629. {
  15630. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15632. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15633. {
  15634. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15635. }
  15636. else
  15637. {
  15638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15639. }
  15640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15641. isKnowKey = TRUE;
  15642. }
  15643. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15644. {
  15645. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15647. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15648. {
  15649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15650. }
  15651. else
  15652. {
  15653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15654. }
  15655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15656. isKnowKey = TRUE;
  15657. }
  15658. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15659. {
  15660. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15662. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15663. {
  15664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15665. }
  15666. else
  15667. {
  15668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15669. }
  15670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15671. isKnowKey = TRUE;
  15672. }
  15673. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15674. {
  15675. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15677. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15678. {
  15679. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15680. }
  15681. else
  15682. {
  15683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15684. }
  15685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15686. isKnowKey = TRUE;
  15687. }
  15688. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15689. {
  15690. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15692. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15693. {
  15694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15695. }
  15696. else
  15697. {
  15698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15699. }
  15700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15701. isKnowKey = TRUE;
  15702. }
  15703. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15704. {
  15705. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15707. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15708. {
  15709. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15710. }
  15711. else
  15712. {
  15713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15714. }
  15715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15716. isKnowKey = TRUE;
  15717. }
  15718. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15719. {
  15720. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15722. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15723. {
  15724. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15725. }
  15726. else
  15727. {
  15728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15729. }
  15730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15731. isKnowKey = TRUE;
  15732. }
  15733. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15734. {
  15735. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15737. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15738. {
  15739. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15740. }
  15741. else
  15742. {
  15743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15744. }
  15745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15746. isKnowKey = TRUE;
  15747. }
  15748. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15749. {
  15750. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15752. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15753. {
  15754. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15755. }
  15756. else
  15757. {
  15758. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15759. }
  15760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15761. isKnowKey = TRUE;
  15762. }
  15763. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15764. {
  15765. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15767. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15768. {
  15769. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15770. }
  15771. else
  15772. {
  15773. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15774. }
  15775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15776. isKnowKey = TRUE;
  15777. }
  15778. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15779. {
  15780. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15781. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15782. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15783. {
  15784. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15785. }
  15786. else
  15787. {
  15788. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15789. }
  15790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15791. isKnowKey = TRUE;
  15792. }
  15793. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15794. {
  15795. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15796. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15797. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15798. {
  15799. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15800. }
  15801. else
  15802. {
  15803. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15804. }
  15805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15806. isKnowKey = TRUE;
  15807. }
  15808. /*
  15809. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15810. {
  15811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15813. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15814. {
  15815. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15816. }
  15817. else
  15818. {
  15819. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15820. }
  15821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15822. isKnowKey = TRUE;
  15823. }*/
  15824. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15825. {
  15826. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15828. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15829. {
  15830. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15831. }
  15832. else
  15833. {
  15834. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15835. }
  15836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15837. isKnowKey = TRUE;
  15838. }
  15839. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15840. {
  15841. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15843. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15844. {
  15845. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15846. }
  15847. else
  15848. {
  15849. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15850. }
  15851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15852. isKnowKey = TRUE;
  15853. }
  15854. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15855. {
  15856. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15858. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15859. {
  15860. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15861. }
  15862. else
  15863. {
  15864. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15865. }
  15866. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15867. isKnowKey = TRUE;
  15868. }
  15869. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15870. {
  15871. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15872. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15873. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15874. {
  15875. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15876. }
  15877. else
  15878. {
  15879. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15880. }
  15881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15882. isKnowKey = TRUE;
  15883. }
  15884. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15885. {
  15886. struct sysinfo s_info;
  15887. int error = sysinfo(&s_info);
  15888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15890. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15891. {
  15892. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15893. }
  15894. else
  15895. {
  15896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15897. }
  15898. if(error != 0)
  15899. {
  15900. DEBUG_WARN("System uptime get error: %d\n", error);
  15901. }
  15902. else
  15903. {
  15904. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15905. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15906. }
  15907. isKnowKey = TRUE;
  15908. }
  15909. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15910. {
  15911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15913. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15914. {
  15915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15916. }
  15917. else
  15918. {
  15919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15920. }
  15921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15922. isKnowKey = TRUE;
  15923. }
  15924. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15925. {
  15926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15927. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15928. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15929. {
  15930. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15931. }
  15932. else
  15933. {
  15934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15935. }
  15936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15937. isKnowKey = TRUE;
  15938. }
  15939. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15940. {
  15941. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15943. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15944. {
  15945. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15946. }
  15947. else
  15948. {
  15949. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15950. }
  15951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15952. isKnowKey = TRUE;
  15953. }
  15954. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15955. {
  15956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15958. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15959. {
  15960. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15961. }
  15962. else
  15963. {
  15964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15965. }
  15966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15967. isKnowKey = TRUE;
  15968. }
  15969. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15970. {
  15971. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15973. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15974. {
  15975. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15976. }
  15977. else
  15978. {
  15979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15980. }
  15981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15982. isKnowKey = TRUE;
  15983. }
  15984. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15985. {
  15986. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15988. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15989. {
  15990. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15991. }
  15992. else
  15993. {
  15994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15995. }
  15996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15997. isKnowKey = TRUE;
  15998. }
  15999. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  16000. {
  16001. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  16002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  16003. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16004. {
  16005. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  16006. }
  16007. else
  16008. {
  16009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  16010. }
  16011. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  16012. isKnowKey = TRUE;
  16013. }
  16014. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  16015. {
  16016. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  16017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  16018. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16019. {
  16020. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  16021. }
  16022. else
  16023. {
  16024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  16025. }
  16026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  16027. isKnowKey = TRUE;
  16028. }
  16029. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  16030. {
  16031. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  16032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  16033. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16034. {
  16035. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  16036. }
  16037. else
  16038. {
  16039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  16040. }
  16041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  16042. isKnowKey = TRUE;
  16043. }
  16044. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  16045. {
  16046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  16047. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  16048. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  16049. {
  16050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  16051. }
  16052. else
  16053. {
  16054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  16055. }
  16056. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  16057. isKnowKey = TRUE;
  16058. }
  16059. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16060. {
  16061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16062. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16063. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16064. {
  16065. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16066. }
  16067. else
  16068. {
  16069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16070. }
  16071. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16072. isKnowKey = TRUE;
  16073. }
  16074. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  16075. {
  16076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  16077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  16078. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  16079. {
  16080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  16081. }
  16082. else
  16083. {
  16084. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  16085. }
  16086. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  16087. isKnowKey = TRUE;
  16088. }
  16089. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  16090. {
  16091. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  16092. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  16093. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  16094. {
  16095. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  16096. }
  16097. else
  16098. {
  16099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  16100. }
  16101. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  16102. isKnowKey = TRUE;
  16103. }
  16104. #if 1
  16105. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16106. {
  16107. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16108. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16109. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16110. {
  16111. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16112. }
  16113. else
  16114. {
  16115. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16116. }
  16117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16118. isKnowKey = TRUE;
  16119. }
  16120. #endif
  16121. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16122. {
  16123. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16124. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16125. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16126. {
  16127. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16128. }
  16129. else
  16130. {
  16131. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16132. }
  16133. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16134. isKnowKey = TRUE;
  16135. }
  16136. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16137. {
  16138. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16139. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16140. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16141. {
  16142. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16143. }
  16144. else
  16145. {
  16146. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16147. }
  16148. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16149. isKnowKey = TRUE;
  16150. }
  16151. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16152. {
  16153. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16154. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16155. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16156. {
  16157. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16158. }
  16159. else
  16160. {
  16161. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16162. }
  16163. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16164. isKnowKey = TRUE;
  16165. }
  16166. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16167. {
  16168. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16169. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16170. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16171. {
  16172. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16173. }
  16174. else
  16175. {
  16176. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16177. }
  16178. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16179. isKnowKey = TRUE;
  16180. }
  16181. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16182. {
  16183. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16184. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16185. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16186. {
  16187. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16188. }
  16189. else
  16190. {
  16191. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16192. }
  16193. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16194. isKnowKey = TRUE;
  16195. }
  16196. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16197. {
  16198. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16199. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16200. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16201. {
  16202. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16203. }
  16204. else
  16205. {
  16206. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16207. }
  16208. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16209. isKnowKey = TRUE;
  16210. }
  16211. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16212. {
  16213. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16214. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16215. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16216. {
  16217. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16218. }
  16219. else
  16220. {
  16221. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16222. }
  16223. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16224. isKnowKey = TRUE;
  16225. }
  16226. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16227. {
  16228. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16229. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16230. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16231. {
  16232. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16233. }
  16234. else
  16235. {
  16236. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16237. }
  16238. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16239. isKnowKey = TRUE;
  16240. }
  16241. //=========================================================
  16242. if(!isEmpty && !isKnowKey)
  16243. {
  16244. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16245. strcpy(unknownkey[UnknownKeynum], keyReq);
  16246. UnknownKeynum = UnknownKeynum + 1;
  16247. }
  16248. }
  16249. void processUnkownKey(void)
  16250. {
  16251. DEBUG_INFO("processUnkownKey...\n");
  16252. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16253. for(int index=0; index < UnknownKeynum; index++)
  16254. {
  16255. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16256. {
  16257. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16258. }
  16259. }
  16260. }
  16261. int setKeyValue(char *key, char *value)
  16262. {
  16263. int isSuccess = NotSupported;
  16264. int check_ascii=0;
  16265. char str[501]={0};
  16266. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16267. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16268. {
  16269. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16270. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16271. {
  16272. strcpy(str, (const char*)value);
  16273. for(int i = 0; str[i]; i++){
  16274. str[i] = tolower(str[i]);
  16275. }
  16276. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].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, "AuthorizationCacheEnabled") == 0)
  16285. {
  16286. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16287. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16288. {
  16289. strcpy(str, (const char*)value);
  16290. for(int i = 0; str[i]; i++){
  16291. str[i] = tolower(str[i]);
  16292. }
  16293. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16294. isSuccess = ConfigurationStatus_Accepted;
  16295. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  16296. }
  16297. else
  16298. {
  16299. isSuccess = ConfigurationStatus_Rejected;
  16300. }
  16301. }
  16302. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16303. {
  16304. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16305. {
  16306. strcpy(str, (const char*)value);
  16307. for(int i = 0; str[i]; i++)
  16308. {
  16309. str[i] = tolower(str[i]);
  16310. }
  16311. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16312. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16313. isSuccess = ConfigurationStatus_Accepted;
  16314. }
  16315. else
  16316. {
  16317. isSuccess = ConfigurationStatus_Rejected;
  16318. }
  16319. }
  16320. if(strcmp(key, "BlinkRepeat") == 0)
  16321. {
  16322. //Charger.BlinkRepeat = Integer.parseInt(value);
  16323. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16324. {
  16325. check_ascii = value[0];
  16326. if( (check_ascii < 48) || (check_ascii > 57) )
  16327. {
  16328. isSuccess = ConfigurationStatus_Rejected;
  16329. }
  16330. else
  16331. {
  16332. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16333. isSuccess = ConfigurationStatus_Accepted;
  16334. }
  16335. }
  16336. else
  16337. {
  16338. isSuccess = ConfigurationStatus_Rejected;
  16339. }
  16340. }
  16341. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16342. {
  16343. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16344. {
  16345. check_ascii = value[0];
  16346. if( (check_ascii < 48) || (check_ascii > 57) )
  16347. {
  16348. isSuccess = ConfigurationStatus_Rejected;
  16349. }
  16350. else
  16351. {
  16352. if((atoi(value) == 0) || (atoi(value) >= 5))
  16353. {
  16354. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16355. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16356. isSuccess = ConfigurationStatus_Accepted;
  16357. }
  16358. else
  16359. isSuccess = ConfigurationStatus_Rejected;
  16360. }
  16361. }
  16362. else
  16363. {
  16364. isSuccess = ConfigurationStatus_Rejected;
  16365. }
  16366. }
  16367. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16368. {
  16369. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16370. {
  16371. check_ascii = value[0];
  16372. if( (check_ascii < 48) || (check_ascii > 57) )
  16373. {
  16374. isSuccess = ConfigurationStatus_Rejected;
  16375. }
  16376. else
  16377. {
  16378. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16379. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16380. isSuccess = ConfigurationStatus_Accepted;
  16381. }
  16382. }
  16383. else
  16384. {
  16385. isSuccess = ConfigurationStatus_Rejected;
  16386. }
  16387. }
  16388. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16389. {
  16390. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16391. {
  16392. check_ascii = value[0];
  16393. if( (check_ascii < 48) || (check_ascii > 57) )
  16394. {
  16395. isSuccess = ConfigurationStatus_Rejected;
  16396. }
  16397. else
  16398. {
  16399. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16400. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16401. isSuccess = ConfigurationStatus_Accepted;
  16402. }
  16403. }
  16404. else
  16405. {
  16406. isSuccess = ConfigurationStatus_Rejected;
  16407. }
  16408. }
  16409. if(strcmp(key, "HeartbeatInterval") == 0)
  16410. {
  16411. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16412. {
  16413. check_ascii = value[0];
  16414. if( (check_ascii < 48) || (check_ascii > 57) )
  16415. {
  16416. isSuccess = ConfigurationStatus_Rejected;
  16417. }
  16418. else
  16419. {
  16420. if((atoi(value) == 0) || (atoi(value) >= 10))
  16421. {
  16422. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16423. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16424. HeartBeatWaitTime = atoi(value);
  16425. isSuccess = ConfigurationStatus_Accepted;
  16426. }
  16427. else
  16428. {
  16429. isSuccess = ConfigurationStatus_Rejected;
  16430. }
  16431. }
  16432. }
  16433. else
  16434. {
  16435. isSuccess = ConfigurationStatus_Rejected;
  16436. }
  16437. }
  16438. if(strcmp(key, "LightIntensity") == 0)
  16439. {
  16440. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16441. {
  16442. check_ascii = value[0];
  16443. if( (check_ascii < 48) || (check_ascii > 57) )
  16444. {
  16445. isSuccess = ConfigurationStatus_Rejected;
  16446. }
  16447. else
  16448. {
  16449. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16450. isSuccess = ConfigurationStatus_Accepted;
  16451. }
  16452. }
  16453. else
  16454. {
  16455. isSuccess = ConfigurationStatus_Rejected;
  16456. }
  16457. }
  16458. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16459. {
  16460. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16461. {
  16462. strcpy(str, (const char*)value);
  16463. for(int i = 0; str[i]; i++)
  16464. {
  16465. str[i] = tolower(str[i]);
  16466. }
  16467. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16468. isSuccess = ConfigurationStatus_Accepted;
  16469. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16470. }
  16471. else
  16472. {
  16473. isSuccess = ConfigurationStatus_Rejected;
  16474. }
  16475. }
  16476. if(strcmp(key, "LocalPreAuthorize") == 0)
  16477. {
  16478. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16479. {
  16480. strcpy(str, (const char*)value);
  16481. for(int i = 0; str[i]; i++)
  16482. {
  16483. str[i] = tolower(str[i]);
  16484. }
  16485. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16486. isSuccess = ConfigurationStatus_Accepted;
  16487. }
  16488. else
  16489. {
  16490. isSuccess = ConfigurationStatus_Rejected;
  16491. }
  16492. }
  16493. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16494. {
  16495. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16496. {
  16497. check_ascii = value[0];
  16498. if( (check_ascii < 48) || (check_ascii > 57) )
  16499. {
  16500. isSuccess = ConfigurationStatus_Rejected;
  16501. }
  16502. else
  16503. {
  16504. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16505. isSuccess = ConfigurationStatus_Accepted;
  16506. }
  16507. }
  16508. else
  16509. {
  16510. isSuccess = ConfigurationStatus_Rejected;
  16511. }
  16512. }
  16513. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16514. {
  16515. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16516. {
  16517. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16518. isSuccess = ConfigurationStatus_Accepted;
  16519. }
  16520. else
  16521. {
  16522. isSuccess = ConfigurationStatus_Rejected;
  16523. }
  16524. }
  16525. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16526. {
  16527. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16528. {
  16529. check_ascii = value[0];
  16530. if( (check_ascii < 48) || (check_ascii > 57) )
  16531. {
  16532. isSuccess = ConfigurationStatus_Rejected;
  16533. }
  16534. else
  16535. {
  16536. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16537. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16538. isSuccess = ConfigurationStatus_Accepted;
  16539. }
  16540. }
  16541. else
  16542. {
  16543. isSuccess = ConfigurationStatus_Rejected;
  16544. }
  16545. }
  16546. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16547. {
  16548. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16549. {
  16550. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16551. isSuccess = ConfigurationStatus_Accepted;
  16552. }
  16553. else
  16554. {
  16555. isSuccess = ConfigurationStatus_Rejected;
  16556. }
  16557. }
  16558. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16559. {
  16560. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16561. {
  16562. check_ascii = value[0];
  16563. if( (check_ascii < 48) || (check_ascii > 57) )
  16564. {
  16565. isSuccess = ConfigurationStatus_Rejected;
  16566. }
  16567. else
  16568. {
  16569. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16570. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16571. isSuccess = ConfigurationStatus_Accepted;
  16572. }
  16573. }
  16574. else
  16575. {
  16576. isSuccess = ConfigurationStatus_Rejected;
  16577. }
  16578. }
  16579. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16580. {
  16581. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16582. {
  16583. check_ascii = value[0];
  16584. if( (check_ascii < 48) || (check_ascii > 57) )
  16585. {
  16586. isSuccess = ConfigurationStatus_Rejected;
  16587. }
  16588. else
  16589. {
  16590. if((atoi(value) == 0) || (atoi(value) >= 3))
  16591. {
  16592. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16593. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16594. isSuccess = ConfigurationStatus_Accepted;
  16595. }
  16596. else
  16597. {
  16598. isSuccess = ConfigurationStatus_Rejected;
  16599. }
  16600. }
  16601. }
  16602. else
  16603. {
  16604. isSuccess = ConfigurationStatus_Rejected;
  16605. }
  16606. }
  16607. if(strcmp(key, "MinimumStatusDuration") == 0)
  16608. {
  16609. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16610. {
  16611. check_ascii = value[0];
  16612. if( (check_ascii < 48) || (check_ascii > 57) )
  16613. {
  16614. isSuccess = ConfigurationStatus_Rejected;
  16615. }
  16616. else
  16617. {
  16618. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16619. {
  16620. isSuccess = ConfigurationStatus_Rejected;
  16621. }
  16622. else
  16623. {
  16624. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16625. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16626. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16627. isSuccess = ConfigurationStatus_Accepted;
  16628. }
  16629. }
  16630. }
  16631. else
  16632. {
  16633. isSuccess = ConfigurationStatus_Rejected;
  16634. }
  16635. }
  16636. if(strcmp(key, "NumberOfConnectors") == 0)
  16637. {
  16638. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16639. {
  16640. check_ascii = value[0];
  16641. if( (check_ascii < 48) || (check_ascii > 57) )
  16642. {
  16643. isSuccess = ConfigurationStatus_Rejected;
  16644. }
  16645. else
  16646. {
  16647. //Charger.ResetRetries = Integer.parseInt(value);
  16648. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16649. isSuccess = ConfigurationStatus_Accepted;
  16650. }
  16651. }
  16652. else
  16653. {
  16654. isSuccess = ConfigurationStatus_Rejected;
  16655. }
  16656. }
  16657. if(strcmp(key, "ResetRetries") == 0)
  16658. {
  16659. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16660. {
  16661. check_ascii = value[0];
  16662. if( (check_ascii < 48) || (check_ascii > 57) )
  16663. {
  16664. isSuccess = ConfigurationStatus_Rejected;
  16665. }
  16666. else
  16667. {
  16668. //Charger.ResetRetries = Integer.parseInt(value);
  16669. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16670. isSuccess = ConfigurationStatus_Accepted;
  16671. }
  16672. }
  16673. else
  16674. {
  16675. isSuccess = ConfigurationStatus_Rejected;
  16676. }
  16677. }
  16678. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16679. {
  16680. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16681. {
  16682. strcpy(str, (const char*)value);
  16683. for(int i = 0; str[i]; i++)
  16684. {
  16685. str[i] = tolower(str[i]);
  16686. }
  16687. if(strcmp(str, "notapplicable")== 0)
  16688. {
  16689. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16690. isSuccess = ConfigurationStatus_Accepted;
  16691. }
  16692. else if(strcmp(str, "unknown")== 0)
  16693. {
  16694. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16695. isSuccess = ConfigurationStatus_Accepted;
  16696. }
  16697. else if(strcmp(str, "rst")== 0)
  16698. {
  16699. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16700. isSuccess = ConfigurationStatus_Accepted;
  16701. }
  16702. else if(strcmp(str, "rts")== 0)
  16703. {
  16704. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16705. isSuccess = ConfigurationStatus_Accepted;
  16706. }
  16707. else if(strcmp(str, "srt")== 0)
  16708. {
  16709. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16710. isSuccess = ConfigurationStatus_Accepted;
  16711. }
  16712. else if(strcmp(str, "str")== 0)
  16713. {
  16714. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16715. isSuccess = ConfigurationStatus_Accepted;
  16716. }
  16717. else if(strcmp(str, "trs")== 0)
  16718. {
  16719. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16720. isSuccess = ConfigurationStatus_Accepted;
  16721. }
  16722. else if(strcmp(str, "tsr")== 0)
  16723. {
  16724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16725. isSuccess = ConfigurationStatus_Accepted;
  16726. }
  16727. else
  16728. {
  16729. isSuccess = ConfigurationStatus_Rejected;
  16730. }
  16731. }
  16732. else
  16733. {
  16734. isSuccess = ConfigurationStatus_Rejected;
  16735. }
  16736. }
  16737. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16738. {
  16739. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16740. {
  16741. check_ascii = value[0];
  16742. if( (check_ascii < 48) || (check_ascii > 57) )
  16743. {
  16744. isSuccess = ConfigurationStatus_Rejected;
  16745. }
  16746. else
  16747. {
  16748. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16749. isSuccess = ConfigurationStatus_Accepted;
  16750. }
  16751. }
  16752. else
  16753. {
  16754. isSuccess = ConfigurationStatus_Rejected;
  16755. }
  16756. }
  16757. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16758. {
  16759. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16760. {
  16761. strcpy(str, (const char*)value);
  16762. for(int i = 0; str[i]; i++)
  16763. {
  16764. str[i] = tolower(str[i]);
  16765. }
  16766. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16767. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16768. isSuccess = ConfigurationStatus_Accepted;
  16769. }
  16770. else
  16771. {
  16772. isSuccess = ConfigurationStatus_Rejected;
  16773. }
  16774. }
  16775. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16776. {
  16777. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16778. {
  16779. strcpy(str, (const char*)value);
  16780. for(int i = 0; str[i]; i++)
  16781. {
  16782. str[i] = tolower(str[i]);
  16783. }
  16784. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16785. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16786. isSuccess = ConfigurationStatus_Accepted;
  16787. }
  16788. else
  16789. {
  16790. isSuccess = ConfigurationStatus_Rejected;
  16791. }
  16792. }
  16793. if(strcmp(key, "StopTxnAlignedData") == 0)
  16794. {
  16795. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16796. {
  16797. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16798. isSuccess = ConfigurationStatus_Accepted;
  16799. }
  16800. else
  16801. {
  16802. isSuccess = ConfigurationStatus_Rejected;
  16803. }
  16804. }
  16805. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16806. {
  16807. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16808. {
  16809. check_ascii = value[0];
  16810. if( (check_ascii < 48) || (check_ascii > 57) )
  16811. {
  16812. isSuccess = ConfigurationStatus_Rejected;
  16813. }
  16814. else
  16815. {
  16816. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16817. isSuccess = ConfigurationStatus_Accepted;
  16818. }
  16819. }
  16820. else
  16821. {
  16822. isSuccess = ConfigurationStatus_Rejected;
  16823. }
  16824. }
  16825. if(strcmp(key, "StopTxnSampledData") == 0)
  16826. {
  16827. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16828. {
  16829. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16830. isSuccess = ConfigurationStatus_Accepted;
  16831. }
  16832. else
  16833. {
  16834. isSuccess = ConfigurationStatus_Rejected;
  16835. }
  16836. }
  16837. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16838. {
  16839. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16840. {
  16841. check_ascii = value[0];
  16842. if( (check_ascii < 48) || (check_ascii > 57) )
  16843. {
  16844. isSuccess = ConfigurationStatus_Rejected;
  16845. }
  16846. else
  16847. {
  16848. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16849. isSuccess = ConfigurationStatus_Accepted;
  16850. }
  16851. }
  16852. else
  16853. {
  16854. isSuccess = ConfigurationStatus_Rejected;
  16855. }
  16856. }
  16857. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16858. {
  16859. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16860. {
  16861. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16862. isSuccess = ConfigurationStatus_Accepted;
  16863. }
  16864. else
  16865. {
  16866. isSuccess = ConfigurationStatus_Rejected;
  16867. }
  16868. }
  16869. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16870. {
  16871. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16872. {
  16873. check_ascii = value[0];
  16874. if( (check_ascii < 48) || (check_ascii > 57) )
  16875. {
  16876. isSuccess = ConfigurationStatus_Rejected;
  16877. }
  16878. else
  16879. {
  16880. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16881. isSuccess = ConfigurationStatus_Accepted;
  16882. }
  16883. }
  16884. else
  16885. {
  16886. isSuccess = ConfigurationStatus_Rejected;
  16887. }
  16888. }
  16889. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16890. {
  16891. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16892. {
  16893. check_ascii = value[0];
  16894. if( (check_ascii < 48) || (check_ascii > 57) )
  16895. {
  16896. isSuccess = ConfigurationStatus_Rejected;
  16897. }
  16898. else
  16899. {
  16900. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16901. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16902. TransactionMessageAttemptsValue = atoi(value);
  16903. isSuccess = ConfigurationStatus_Accepted;
  16904. }
  16905. }
  16906. else
  16907. {
  16908. isSuccess = ConfigurationStatus_Rejected;
  16909. }
  16910. }
  16911. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16912. {
  16913. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16914. {
  16915. check_ascii = value[0];
  16916. if( (check_ascii < 48) || (check_ascii > 57) )
  16917. {
  16918. isSuccess = ConfigurationStatus_Rejected;
  16919. }
  16920. else
  16921. {
  16922. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16923. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16924. TransactionMessageRetryIntervalValue = atoi(value);
  16925. isSuccess = ConfigurationStatus_Accepted;
  16926. }
  16927. }
  16928. else
  16929. {
  16930. isSuccess = ConfigurationStatus_Rejected;
  16931. }
  16932. }
  16933. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16934. {
  16935. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16936. {
  16937. strcpy(str, (const char*)value);
  16938. for(int i = 0; str[i]; i++)
  16939. {
  16940. str[i] = tolower(str[i]);
  16941. }
  16942. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16943. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16944. isSuccess = ConfigurationStatus_Accepted;
  16945. }
  16946. else
  16947. {
  16948. isSuccess = ConfigurationStatus_Rejected;
  16949. }
  16950. }
  16951. if(strcmp(key, "WebSocketPingInterval") == 0)
  16952. {
  16953. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16954. {
  16955. check_ascii = value[0];
  16956. if( (check_ascii < 48) || (check_ascii > 57) )
  16957. {
  16958. isSuccess = ConfigurationStatus_Rejected;
  16959. }
  16960. else
  16961. {
  16962. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16963. isSuccess = ConfigurationStatus_Accepted;
  16964. if((atoi(value) == 0) || (atoi(value) >= 10))
  16965. {
  16966. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16967. isSuccess = ConfigurationStatus_Accepted;
  16968. }
  16969. else
  16970. isSuccess = ConfigurationStatus_Rejected;
  16971. }
  16972. }
  16973. else
  16974. {
  16975. isSuccess = ConfigurationStatus_Rejected;
  16976. }
  16977. }
  16978. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16979. {
  16980. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16981. {
  16982. strcpy(str, (const char*)value);
  16983. for(int i = 0; str[i]; i++)
  16984. {
  16985. str[i] = tolower(str[i]);
  16986. }
  16987. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16988. isSuccess = ConfigurationStatus_Accepted;
  16989. }
  16990. else
  16991. {
  16992. isSuccess = ConfigurationStatus_Rejected;
  16993. }
  16994. }
  16995. if(strcmp(key, "AuthorizationKey") == 0)
  16996. {
  16997. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16998. {
  16999. strcpy(str, (const char*)value);
  17000. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  17001. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17002. isSuccess = ConfigurationStatus_Accepted;
  17003. }
  17004. else
  17005. {
  17006. isSuccess = ConfigurationStatus_Rejected;
  17007. }
  17008. }
  17009. if(strcmp(key, "SecurityProfile") == 0)
  17010. {
  17011. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17012. {
  17013. check_ascii = value[0];
  17014. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  17015. {
  17016. isSuccess = ConfigurationStatus_Rejected;
  17017. }
  17018. else if(check_ascii == 0x33)
  17019. {
  17020. isSuccess = NotSupported;
  17021. }
  17022. else
  17023. {
  17024. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  17025. {
  17026. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  17027. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  17028. isSuccess = ConfigurationStatus_Accepted;
  17029. }
  17030. else
  17031. isSuccess = ConfigurationStatus_Rejected;
  17032. }
  17033. }
  17034. else
  17035. {
  17036. isSuccess = ConfigurationStatus_Rejected;
  17037. }
  17038. }
  17039. if(strcmp(key, "DefaultPrice") == 0)
  17040. {
  17041. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  17042. {
  17043. strcpy(str, (const char*)value);
  17044. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  17045. isSuccess = ConfigurationStatus_Accepted;
  17046. }
  17047. else
  17048. {
  17049. isSuccess = ConfigurationStatus_Rejected;
  17050. }
  17051. }
  17052. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  17053. {
  17054. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17055. {
  17056. strcpy(str, (const char*)value);
  17057. for(int i = 0; str[i]; i++)
  17058. {
  17059. str[i] = tolower(str[i]);
  17060. }
  17061. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17062. isSuccess = ConfigurationStatus_Accepted;
  17063. }
  17064. else
  17065. {
  17066. isSuccess = ConfigurationStatus_Rejected;
  17067. }
  17068. }
  17069. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  17070. {
  17071. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17072. {
  17073. strcpy(str, (const char*)value);
  17074. for(int i = 0; str[i]; i++)
  17075. {
  17076. str[i] = tolower(str[i]);
  17077. }
  17078. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17079. isSuccess = ConfigurationStatus_Accepted;
  17080. }
  17081. else
  17082. {
  17083. isSuccess = ConfigurationStatus_Rejected;
  17084. }
  17085. }
  17086. if(strcmp(key, "SystemUptimeSec") == 0)
  17087. {
  17088. isSuccess = NotSupported;
  17089. }
  17090. if(strcmp(key, "FreeVend") == 0)
  17091. {
  17092. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17093. {
  17094. strcpy(str, (const char*)value);
  17095. for(int i = 0; str[i]; i++)
  17096. {
  17097. str[i] = tolower(str[i]);
  17098. }
  17099. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17100. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17101. isSuccess = ConfigurationStatus_Accepted;
  17102. }
  17103. else
  17104. {
  17105. isSuccess = ConfigurationStatus_Rejected;
  17106. }
  17107. }
  17108. if(strcmp(key, "FreeVendIdtag") == 0)
  17109. {
  17110. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17111. {
  17112. strcpy(str, (const char*)value);
  17113. if(strlen(str) <= 20)
  17114. {
  17115. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17116. isSuccess = ConfigurationStatus_Accepted;
  17117. }
  17118. else
  17119. {
  17120. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17121. isSuccess = ConfigurationStatus_Rejected;
  17122. }
  17123. }
  17124. else
  17125. {
  17126. isSuccess = ConfigurationStatus_Rejected;
  17127. }
  17128. }
  17129. if(strcmp(key, "OcppServer") == 0)
  17130. {
  17131. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17132. {
  17133. strcpy(str, (const char*)value);
  17134. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17135. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17136. isSuccess = ConfigurationStatus_Accepted;
  17137. }
  17138. else
  17139. {
  17140. isSuccess = ConfigurationStatus_Rejected;
  17141. }
  17142. }
  17143. if(strcmp(key, "MaintainServer") == 0)
  17144. {
  17145. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17146. {
  17147. strcpy(str, (const char*)value);
  17148. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17149. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17150. isSuccess = ConfigurationStatus_Accepted;
  17151. }
  17152. else
  17153. {
  17154. isSuccess = ConfigurationStatus_Rejected;
  17155. }
  17156. }
  17157. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17158. {
  17159. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17160. {
  17161. strcpy(str, (const char*)value);
  17162. for(int i = 0; str[i]; i++)
  17163. {
  17164. str[i] = tolower(str[i]);
  17165. }
  17166. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17167. isSuccess = ConfigurationStatus_Accepted;
  17168. }
  17169. else
  17170. {
  17171. isSuccess = ConfigurationStatus_Rejected;
  17172. }
  17173. }
  17174. if(strcmp(key, "StatusNotificationInterval") == 0)
  17175. {
  17176. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17177. {
  17178. check_ascii = value[0];
  17179. if( (check_ascii < 48) || (check_ascii > 57) )
  17180. {
  17181. isSuccess = ConfigurationStatus_Rejected;
  17182. }
  17183. else
  17184. {
  17185. if((atoi(value) == 0) || (atoi(value) >= 10))
  17186. {
  17187. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17188. isSuccess = ConfigurationStatus_Accepted;
  17189. }
  17190. else
  17191. isSuccess = ConfigurationStatus_Rejected;
  17192. }
  17193. }
  17194. else
  17195. {
  17196. isSuccess = ConfigurationStatus_Rejected;
  17197. }
  17198. }
  17199. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17200. {
  17201. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17202. {
  17203. check_ascii = value[0];
  17204. if( (check_ascii < 48) || (check_ascii > 57) )
  17205. {
  17206. isSuccess = ConfigurationStatus_Rejected;
  17207. }
  17208. else
  17209. {
  17210. if(atoi(value) >= 0)
  17211. {
  17212. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value) );
  17213. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17214. isSuccess = ConfigurationStatus_Accepted;
  17215. }
  17216. else
  17217. isSuccess = ConfigurationStatus_Rejected;
  17218. }
  17219. }
  17220. else
  17221. {
  17222. isSuccess = ConfigurationStatus_Rejected;
  17223. }
  17224. }
  17225. if(strcmp(key, "PowerSharingServerIP") == 0)
  17226. {
  17227. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17228. {
  17229. strcpy(str, (const char*)value);
  17230. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17231. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17232. isSuccess = ConfigurationStatus_Accepted;
  17233. }
  17234. else
  17235. {
  17236. isSuccess = ConfigurationStatus_Rejected;
  17237. }
  17238. }
  17239. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17240. {
  17241. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17242. {
  17243. strcpy(str, (const char*)value);
  17244. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17245. isSuccess = ConfigurationStatus_Accepted;
  17246. }
  17247. else
  17248. {
  17249. isSuccess = ConfigurationStatus_Rejected;
  17250. }
  17251. }
  17252. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  17253. {
  17254. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17255. {
  17256. if(atoi(value) > modelnameInfo.ratedPower)
  17257. {
  17258. isSuccess = ConfigurationStatus_Rejected;
  17259. }
  17260. else{
  17261. strcpy(str, (const char*)value);
  17262. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  17263. isSuccess = ConfigurationStatus_Accepted;
  17264. }
  17265. }
  17266. else
  17267. {
  17268. isSuccess = ConfigurationStatus_Rejected;
  17269. }
  17270. }
  17271. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  17272. {
  17273. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17274. {
  17275. if((atoi(value) != 0) && (atoi(value) < 5))
  17276. {
  17277. isSuccess = ConfigurationStatus_Rejected;
  17278. }
  17279. else{
  17280. strcpy(str, (const char*)value);
  17281. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  17282. isSuccess = ConfigurationStatus_Accepted;
  17283. }
  17284. }
  17285. else
  17286. {
  17287. isSuccess = ConfigurationStatus_Rejected;
  17288. }
  17289. }
  17290. #if 0
  17291. //For OCPP Test Case
  17292. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17293. {
  17294. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17295. {
  17296. strcpy(str, (const char*)value);
  17297. for(int i = 0; str[i]; i++)
  17298. {
  17299. str[i] = tolower(str[i]);
  17300. }
  17301. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17302. isSuccess = ConfigurationStatus_Accepted;
  17303. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17304. }
  17305. else
  17306. {
  17307. isSuccess = ConfigurationStatus_Rejected;
  17308. }
  17309. }
  17310. #endif
  17311. #if 1
  17312. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17313. {
  17314. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17315. {
  17316. strcpy(str, (const char*)value);
  17317. for(int i = 0; str[i]; i++)
  17318. {
  17319. str[i] = tolower(str[i]);
  17320. }
  17321. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17322. isSuccess = ConfigurationStatus_Accepted;
  17323. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17324. }
  17325. else
  17326. {
  17327. isSuccess = ConfigurationStatus_Rejected;
  17328. }
  17329. }
  17330. #endif
  17331. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17332. {
  17333. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17334. {
  17335. check_ascii = value[0];
  17336. if( (check_ascii < 48) || (check_ascii > 57) )
  17337. {
  17338. isSuccess = ConfigurationStatus_Rejected;
  17339. }
  17340. else
  17341. {
  17342. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17343. isSuccess = ConfigurationStatus_Accepted;
  17344. }
  17345. }
  17346. else
  17347. {
  17348. isSuccess = ConfigurationStatus_Rejected;
  17349. }
  17350. }
  17351. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17352. {
  17353. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17354. {
  17355. check_ascii = value[0];
  17356. if( (check_ascii < 48) || (check_ascii > 57) )
  17357. {
  17358. isSuccess = ConfigurationStatus_Rejected;
  17359. }
  17360. else
  17361. {
  17362. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17363. isSuccess = ConfigurationStatus_Accepted;
  17364. }
  17365. }
  17366. else
  17367. {
  17368. isSuccess = ConfigurationStatus_Rejected;
  17369. }
  17370. }
  17371. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17372. {
  17373. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17374. {
  17375. strcpy(str, (const char*)value);
  17376. for(int i = 0; str[i]; i++)
  17377. {
  17378. str[i] = tolower(str[i]);
  17379. }
  17380. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17381. isSuccess = ConfigurationStatus_Accepted;
  17382. }
  17383. else
  17384. {
  17385. isSuccess = ConfigurationStatus_Rejected;
  17386. }
  17387. }
  17388. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17389. {
  17390. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17391. {
  17392. check_ascii = value[0];
  17393. if( (check_ascii < 48) || (check_ascii > 57) )
  17394. {
  17395. isSuccess = ConfigurationStatus_Rejected;
  17396. }
  17397. else
  17398. {
  17399. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17400. isSuccess = ConfigurationStatus_Accepted;
  17401. }
  17402. }
  17403. else
  17404. {
  17405. isSuccess = ConfigurationStatus_Rejected;
  17406. }
  17407. }
  17408. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17409. {
  17410. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17411. {
  17412. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17413. isSuccess = ConfigurationStatus_Accepted;
  17414. }
  17415. else
  17416. {
  17417. isSuccess = ConfigurationStatus_Rejected;
  17418. }
  17419. }
  17420. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17421. {
  17422. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17423. {
  17424. check_ascii = value[0];
  17425. if( (check_ascii < 48) || (check_ascii > 57) )
  17426. {
  17427. isSuccess = ConfigurationStatus_Rejected;
  17428. }
  17429. else
  17430. {
  17431. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17432. isSuccess = ConfigurationStatus_Accepted;
  17433. }
  17434. }
  17435. else
  17436. {
  17437. isSuccess = ConfigurationStatus_Rejected;
  17438. }
  17439. }
  17440. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17441. {
  17442. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17443. {
  17444. strcpy(str, (const char*)value);
  17445. for(int i = 0; str[i]; i++)
  17446. {
  17447. str[i] = tolower(str[i]);
  17448. }
  17449. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17450. isSuccess = ConfigurationStatus_Accepted;
  17451. }
  17452. else
  17453. {
  17454. isSuccess = ConfigurationStatus_Rejected;
  17455. }
  17456. }
  17457. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17458. {
  17459. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17460. {
  17461. check_ascii = value[0];
  17462. if( (check_ascii < 48) || (check_ascii > 57) )
  17463. {
  17464. isSuccess = ConfigurationStatus_Rejected;
  17465. }
  17466. else
  17467. {
  17468. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17469. isSuccess = ConfigurationStatus_Accepted;
  17470. }
  17471. }
  17472. else
  17473. {
  17474. isSuccess = ConfigurationStatus_Rejected;
  17475. }
  17476. }
  17477. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17478. return isSuccess;
  17479. }
  17480. int TransactionMessageAttemptsGet(void)
  17481. {
  17482. return TransactionMessageAttemptsValue;
  17483. }
  17484. int FirstHeartBeatResponse(void)
  17485. {
  17486. return FirstHeartBeat;
  17487. }
  17488. int TransactionMessageRetryIntervalGet(void)
  17489. {
  17490. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17491. }
  17492. int ReadHttpStatus(int sock)
  17493. {
  17494. //char c;
  17495. char buff[1024]="",*ptr=buff+1;
  17496. int bytes_received, status;
  17497. DEBUG_INFO("Begin Response ..\n");
  17498. while((bytes_received = recv(sock, ptr, 1, 0))){
  17499. if(bytes_received==-1){
  17500. perror("ReadHttpStatus");
  17501. exit(1);
  17502. }
  17503. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17504. ptr++;
  17505. }
  17506. *ptr=0;
  17507. ptr=buff+1;
  17508. sscanf(ptr,"%*s %d ", &status);
  17509. DEBUG_INFO("%s\n",ptr);
  17510. DEBUG_INFO("status=%d\n",status);
  17511. DEBUG_INFO("End Response ..\n");
  17512. return (bytes_received>0)?status:0;
  17513. }
  17514. //the only filed that it parsed is 'Content-Length'
  17515. int ParseHeader(int sock)
  17516. {
  17517. //char c;
  17518. char buff[1024]="",*ptr=buff+4;
  17519. int bytes_received;
  17520. DEBUG_INFO("Begin HEADER ..\n");
  17521. while((bytes_received = recv(sock, ptr, 1, 0))){
  17522. if(bytes_received==-1){
  17523. perror("Parse Header");
  17524. exit(1);
  17525. }
  17526. if(
  17527. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17528. (ptr[-1]=='\r') && (*ptr=='\n' )
  17529. ) break;
  17530. ptr++;
  17531. }
  17532. *ptr=0;
  17533. ptr=buff+4;
  17534. //printf("%s",ptr);
  17535. if(bytes_received){
  17536. ptr=strstr(ptr,"Content-Length:");
  17537. if(ptr){
  17538. sscanf(ptr,"%*s %d",&bytes_received);
  17539. }else
  17540. bytes_received=-1; //unknown size
  17541. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17542. }
  17543. DEBUG_INFO("End HEADER ..\n");
  17544. return bytes_received ;
  17545. }
  17546. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17547. {
  17548. int result = TRUE;
  17549. char rmFileCmd[100]={0};
  17550. char FilePath[100]={0};
  17551. char ftpbuf[200];
  17552. int systemresult;
  17553. sprintf(FilePath,"/mnt/%s",filename);
  17554. system("ping 8.8.8.8 &");
  17555. if((access(FilePath,F_OK))!=-1)
  17556. {
  17557. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17558. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17559. system(rmFileCmd);
  17560. }
  17561. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17562. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17563. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17564. systemresult = system(ftpbuf);
  17565. if(systemresult != 0)
  17566. {
  17567. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17568. result = FALSE;
  17569. }
  17570. system("pkill ping");
  17571. return result;
  17572. }
  17573. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  17574. {
  17575. int result = TRUE;
  17576. char rmFileCmd[100]={0};
  17577. char FilePath[100]={0};
  17578. char ftpbuf[200];
  17579. int systemresult;
  17580. sprintf(FilePath,"/mnt/%s",filename);
  17581. system("ping 8.8.8.8 &");
  17582. if((access(FilePath,F_OK))!=-1)
  17583. {
  17584. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17585. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17586. system(rmFileCmd);
  17587. }
  17588. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17589. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  17590. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17591. systemresult = system(ftpbuf);
  17592. if(systemresult != 0)
  17593. {
  17594. DEBUG_WARN("scp error!\n");
  17595. result = FALSE;
  17596. }
  17597. system("pkill ping");
  17598. return result;
  17599. }
  17600. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17601. {
  17602. int result = TRUE;
  17603. char rmFileCmd[100]={0};
  17604. char FilePath[100]={0};
  17605. char ftpbuf[200];
  17606. int systemresult;
  17607. sprintf(FilePath,"/mnt/%s",filename);
  17608. system("ping 8.8.8.8 &");
  17609. if((access(FilePath,F_OK))!=-1)
  17610. {
  17611. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17612. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17613. system(rmFileCmd);
  17614. }
  17615. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17616. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17617. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17618. systemresult = system(ftpbuf);
  17619. if(systemresult != 0)
  17620. {
  17621. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17622. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17623. systemresult = system(ftpbuf);
  17624. if(systemresult != 0)
  17625. {
  17626. DEBUG_WARN("FTP download fail!\n");
  17627. result = FALSE;
  17628. }
  17629. }
  17630. system("pkill ping");
  17631. return result;
  17632. }
  17633. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17634. {
  17635. char rmFileCmd[100]={0};
  17636. char FilePath[100]={0};
  17637. char buf[512];
  17638. int systemresult = 0;
  17639. //DEBUG_INFO("filename=%s\n",filename);
  17640. //DEBUG_INFO("url=%s\n",url);
  17641. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17642. if((access(FilePath,F_OK))!=-1)
  17643. {
  17644. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17645. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17646. system(rmFileCmd);
  17647. }
  17648. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17649. if(fp == NULL)
  17650. {
  17651. DEBUG_INFO("log is NULL\n");
  17652. return FALSE;
  17653. }
  17654. else
  17655. {
  17656. fprintf(fp, "%s\n", url);
  17657. fprintf(fp, "%s\n", filename);
  17658. fclose(fp);
  17659. }
  17660. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17661. if(phpFP == NULL)
  17662. {
  17663. DEBUG_INFO("PHP upload fail.\n");
  17664. return FALSE;
  17665. }
  17666. else
  17667. {
  17668. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17669. {
  17670. if(strstr(buf, "result") != NULL)
  17671. {
  17672. sscanf(buf, "result: %d", &systemresult);
  17673. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17674. }
  17675. }
  17676. pclose(phpFP);
  17677. }
  17678. if(systemresult != 1)
  17679. {
  17680. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17681. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17682. if(phpFP == NULL)
  17683. {
  17684. DEBUG_WARN("PHP PUT upload fail.\n");
  17685. return FALSE;
  17686. }
  17687. else
  17688. {
  17689. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17690. {
  17691. if(strstr(buf, "result") != NULL)
  17692. {
  17693. sscanf(buf, "result: %d", &systemresult);
  17694. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17695. }
  17696. }
  17697. pclose(phpFP);
  17698. }
  17699. }
  17700. if(systemresult != 1)
  17701. {
  17702. DEBUG_WARN("PHP PUT upload fail.\n");
  17703. return FALSE;
  17704. }
  17705. return TRUE;
  17706. }
  17707. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17708. {
  17709. int result = FALSE;
  17710. char ftpbuf[200];
  17711. int systemresult;
  17712. /*
  17713. // Domaind name transfer to IP address
  17714. struct hostent* server;
  17715. char *IPbuffer;
  17716. server = gethostbyname(location);
  17717. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17718. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17719. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17720. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17721. systemresult = system(ftpbuf);
  17722. if(systemresult != 0)
  17723. {
  17724. DEBUG_INFO("ftpput error!\n");
  17725. }
  17726. else
  17727. {
  17728. result = TRUE;
  17729. DEBUG_INFO("ftpput OK!\n");
  17730. }
  17731. return result;
  17732. }
  17733. int GetOcppServerURL()
  17734. {
  17735. int result = FALSE;
  17736. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17737. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17738. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17739. struct yuarel url;
  17740. char urlStr[512];
  17741. // OCPPPH only
  17742. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  17743. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  17744. {
  17745. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  17746. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17747. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17748. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  17749. if(yuarel_parse(&url, urlStr) != -1)
  17750. {
  17751. sprintf(OcppProtocol, "%s", url.scheme);
  17752. sprintf(OcppHost, "%s", url.host);
  17753. if(url.path == NULL)
  17754. OcppTempPath[0] = '\0';
  17755. else
  17756. sprintf(OcppTempPath, "%s", url.path);
  17757. if(url.port == 0)
  17758. {
  17759. if(strcmp(OcppProtocol, "wss") == 0)
  17760. OcppPort = 443;
  17761. else
  17762. OcppPort = 80;
  17763. }
  17764. else
  17765. OcppPort = url.port;
  17766. result = TRUE;
  17767. }
  17768. }
  17769. else
  17770. {
  17771. strcpy(OcppHost,"");
  17772. }
  17773. return result;
  17774. }
  17775. int GetOcppPath()
  17776. {
  17777. int result = FALSE;
  17778. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  17779. {
  17780. if(OcppTempPath == NULL)
  17781. {
  17782. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  17783. }
  17784. else
  17785. {
  17786. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  17787. }
  17788. result = TRUE;
  17789. goto End;
  17790. }
  17791. else
  17792. {
  17793. strcpy(OcppPath,"");
  17794. }
  17795. End:
  17796. return result;
  17797. }
  17798. int GetOcppPort()
  17799. {
  17800. return OcppPort;
  17801. }
  17802. int GetOcppConnStatus(void)
  17803. {
  17804. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17805. }
  17806. void SetOcppConnStatus(uint8_t status)
  17807. {
  17808. ShmOCPP16DataPH->OcppConnStatus = status;
  17809. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17810. }
  17811. int GetHeartBeatWithNOResponse(void)
  17812. {
  17813. return HeartBeatWithNOResponse;
  17814. }
  17815. void SetHeartBeatWithNOResponse(void)
  17816. {
  17817. HeartBeatWithNOResponse = 0;
  17818. }
  17819. void GetStartTransactionIdTag(int gun_index)
  17820. {
  17821. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17822. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17823. }
  17824. int GetStartTransactionId(int gun_index)
  17825. {
  17826. return ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17827. }
  17828. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17829. {
  17830. char ch;
  17831. FILE *fptr1;
  17832. int temptransactionId;
  17833. char str[100]={0};
  17834. temptransactionId = 0;
  17835. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17836. {
  17837. DEBUG_INFO("IdTag is empty.\n");
  17838. return temptransactionId;
  17839. }
  17840. /*------ Read the file ----------------*/
  17841. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17842. if (!fptr1)
  17843. {
  17844. DEBUG_INFO("QueueTransactionId file open error.\n");
  17845. //printf(" File not found or unable to open the input file!!\n");
  17846. return temptransactionId;
  17847. }
  17848. ch=fgetc(fptr1);
  17849. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17850. rewind(fptr1);
  17851. if(ch!=EOF)
  17852. {
  17853. // printf("%c",ch);
  17854. while (fgets(str, 100, fptr1) != NULL)
  17855. {
  17856. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17857. if(str[0]=='\0')
  17858. {
  17859. break;
  17860. }
  17861. char *revbuf[8] = {0}; // Variable store string split
  17862. int num = 0;// Quantity after string split
  17863. DEBUG_INFO("Transaction queue data= %s\n", str);
  17864. splitstring(str,",",revbuf,&num); // String split
  17865. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17866. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17867. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17868. DEBUG_INFO("------------------------------\n");
  17869. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17870. {
  17871. if(isStopTransaction)
  17872. {
  17873. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17874. {
  17875. temptransactionId = atoi(revbuf[2]);
  17876. //break;
  17877. }
  17878. }
  17879. else
  17880. {
  17881. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17882. {
  17883. temptransactionId = atoi(revbuf[2]);
  17884. //break;
  17885. }
  17886. }
  17887. }
  17888. }
  17889. }
  17890. else
  17891. DEBUG_INFO("EOF\n");
  17892. fclose(fptr1);
  17893. /*------- End of reading ---------------*/
  17894. return temptransactionId;
  17895. }
  17896. void SetTransactionIdZero(int transactionId)
  17897. {
  17898. char ch;
  17899. FILE *fptr1, *fptr2;
  17900. int temptransactionId = 0;
  17901. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17902. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17903. if (!fptr1)
  17904. {
  17905. //printf(" File not found or unable to open the input file!!\n");
  17906. return ;
  17907. }
  17908. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17909. if (!fptr2)
  17910. {
  17911. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17912. fclose(fptr1);
  17913. return ;
  17914. }
  17915. ch=fgetc(fptr1);
  17916. rewind(fptr1);
  17917. if(ch!=EOF)
  17918. {
  17919. // copy all contents to the temporary file except the specific line
  17920. while (fgets(str, 100, fptr1) != NULL)
  17921. {
  17922. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17923. if(str[0]=='\0')
  17924. {
  17925. break;
  17926. }
  17927. char *revbuf[8] = {0};
  17928. int num = 0;
  17929. strcpy(strtemp, str);
  17930. splitstring(str,",",revbuf,&num);
  17931. if(revbuf[2][0] != '\0')
  17932. {
  17933. temptransactionId = atoi(revbuf[2]);
  17934. if(transactionId != temptransactionId)
  17935. {
  17936. fprintf(fptr2, "%s\n", strtemp);
  17937. }
  17938. }
  17939. }
  17940. }
  17941. fclose(fptr1);
  17942. fclose(fptr2);
  17943. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17944. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17945. /*------ Read the file ----------------*/
  17946. }
  17947. int InternetDisconnect(void)
  17948. {
  17949. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17950. }
  17951. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17952. void storeTempStopTransaction(int gun_index)
  17953. {
  17954. char guid[37]={0};
  17955. int tempIndex = 0;
  17956. char TempStopTransaction[256];
  17957. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17958. DEBUG_INFO("storeTempStopTransaction...\n");
  17959. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17960. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17961. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17962. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17963. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17964. {
  17965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17966. {
  17967. tempIndex = ((gun_index==2) ? 1: 0);
  17968. }
  17969. else
  17970. {
  17971. tempIndex = gun_index;
  17972. }
  17973. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17974. {
  17975. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17976. {
  17977. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17978. }
  17979. }// END OF CHAdeMO_QUANTITY
  17980. }
  17981. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17982. {
  17983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17984. {
  17985. tempIndex = ((gun_index==2) ? 1: 0);
  17986. }
  17987. else
  17988. {
  17989. tempIndex = gun_index;
  17990. }
  17991. for (int index = 0; index < CCS_QUANTITY; index++)
  17992. {
  17993. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17994. {
  17995. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17996. }
  17997. }// END OF CCS_QUANTITY
  17998. }
  17999. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18000. {
  18001. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18002. {
  18003. tempIndex = ((gun_index==2) ? 1: 0);
  18004. }
  18005. else
  18006. {
  18007. tempIndex = gun_index;
  18008. }
  18009. for (int index = 0; index < GB_QUANTITY; index++)
  18010. {
  18011. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18012. {
  18013. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  18014. }
  18015. }// END OF GB_QUANTITY
  18016. }
  18017. else if(gunType[gun_index] == GUN_TYPE_DO)
  18018. {
  18019. tempIndex = gun_index;
  18020. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18021. {
  18022. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18023. {
  18024. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  18025. }
  18026. }
  18027. }
  18028. else
  18029. {
  18030. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18031. {
  18032. tempIndex = 2;
  18033. }
  18034. else
  18035. {
  18036. tempIndex = gun_index;
  18037. }
  18038. for (int index = 0; index < AC_QUANTITY; index++)
  18039. {
  18040. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18041. {
  18042. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  18043. }
  18044. }// END OF AC_QUANTITY
  18045. }
  18046. //Stop Transaction Time
  18047. struct timeval tmnow;
  18048. struct tm *tm;
  18049. char buf[28];//, usec_buf[6];
  18050. gettimeofday(&tmnow, NULL);
  18051. time_t t;
  18052. t = time(NULL);
  18053. /*UTC time and date*/
  18054. tm = gmtime(&t);
  18055. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  18056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  18057. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  18058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  18059. random_uuid(guid);
  18060. /***********************************transactionData******************************************************/
  18061. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  18062. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  18063. //=================================
  18064. //1. Transaction_Begin
  18065. //=================================
  18066. //============================== Energy.Active.Import.Interval ===========================================
  18067. //=================================
  18068. //2. Transaction_End
  18069. //=================================
  18070. //2.1====================================== Current.Import L1 ==============================================
  18071. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18072. {
  18073. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  18074. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18075. {
  18076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18077. {
  18078. tempIndex = ((gun_index==2) ? 1: 0);
  18079. }
  18080. else
  18081. {
  18082. tempIndex = gun_index;
  18083. }
  18084. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18085. {
  18086. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18087. {
  18088. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18089. }
  18090. }// End of for CHAdeMO_QUANTITY
  18091. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18092. }
  18093. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18094. {
  18095. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18096. {
  18097. tempIndex = ((gun_index==2) ? 1: 0);
  18098. }
  18099. else
  18100. {
  18101. tempIndex = gun_index;
  18102. }
  18103. for (int index = 0; index < CCS_QUANTITY; index++)
  18104. {
  18105. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18106. {
  18107. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18108. }
  18109. }// End of for CCS_QUANTITY
  18110. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18111. }
  18112. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18113. {
  18114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18115. {
  18116. tempIndex = ((gun_index==2) ? 1: 0);
  18117. }
  18118. else
  18119. {
  18120. tempIndex = gun_index;
  18121. }
  18122. for (int index = 0; index < GB_QUANTITY; index++)
  18123. {
  18124. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18125. {
  18126. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18127. }
  18128. }// End of for GB_QUANTITY
  18129. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18130. }
  18131. else if(gunType[gun_index] == GUN_TYPE_DO)
  18132. {
  18133. tempIndex = gun_index;
  18134. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18135. {
  18136. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18137. {
  18138. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18139. }
  18140. }
  18141. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18142. }
  18143. else
  18144. {
  18145. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18146. {
  18147. tempIndex = 2;
  18148. }
  18149. else
  18150. {
  18151. tempIndex = gun_index;
  18152. }
  18153. for (int index = 0; index < AC_QUANTITY; index++)
  18154. {
  18155. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18156. {
  18157. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18158. }
  18159. }// End of for AC_QUANTITY
  18160. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18161. }
  18162. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18163. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18164. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18165. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18166. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18167. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18168. }
  18169. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18170. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18171. {
  18172. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18173. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18174. {
  18175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18176. {
  18177. tempIndex = ((gun_index==2) ? 1: 0);
  18178. }
  18179. else
  18180. {
  18181. tempIndex = gun_index;
  18182. }
  18183. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18184. {
  18185. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18186. {
  18187. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18188. }
  18189. }// END OF CHAdeMO_QUANTITY
  18190. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18191. }
  18192. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18193. {
  18194. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18195. {
  18196. tempIndex = ((gun_index==2) ? 1: 0);
  18197. }
  18198. else
  18199. {
  18200. tempIndex = gun_index;
  18201. }
  18202. for (int index = 0; index < CCS_QUANTITY; index++)
  18203. {
  18204. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18205. {
  18206. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18207. }
  18208. }// END OF CCS_QUANTITY
  18209. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18210. }
  18211. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18212. {
  18213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18214. {
  18215. tempIndex = ((gun_index==2) ? 1: 0);
  18216. }
  18217. else
  18218. {
  18219. tempIndex = gun_index;
  18220. }
  18221. for (int index = 0; index < GB_QUANTITY; index++)
  18222. {
  18223. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18224. {
  18225. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18226. }
  18227. }// END OF GB_QUANTITY
  18228. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18229. }
  18230. else if(gunType[gun_index] == GUN_TYPE_DO)
  18231. {
  18232. tempIndex = gun_index;
  18233. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18234. {
  18235. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18236. {
  18237. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18238. }
  18239. }
  18240. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18241. }
  18242. else
  18243. {
  18244. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18245. {
  18246. tempIndex = 2;
  18247. }
  18248. else
  18249. {
  18250. tempIndex = gun_index;
  18251. }
  18252. for (int index = 0; index < AC_QUANTITY; index++)
  18253. {
  18254. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18255. {
  18256. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18257. }
  18258. }// END OF AC_QUANTITY
  18259. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18260. }
  18261. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18262. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18263. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18264. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18265. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18266. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18267. }
  18268. //2.3====================================== Power.Active.Import =========================================
  18269. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18270. {
  18271. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18272. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18273. {
  18274. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18275. {
  18276. tempIndex = ((gun_index==2) ? 1: 0);
  18277. }
  18278. else
  18279. {
  18280. tempIndex = gun_index;
  18281. }
  18282. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18283. {
  18284. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18285. {
  18286. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18287. }
  18288. } // End for CHAdeMO_QUANTITY
  18289. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18290. }
  18291. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18292. {
  18293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18294. {
  18295. tempIndex = ((gun_index==2) ? 1: 0);
  18296. }
  18297. else
  18298. {
  18299. tempIndex = gun_index;
  18300. }
  18301. for (int index = 0; index < CCS_QUANTITY; index++)
  18302. {
  18303. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18304. {
  18305. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18306. }
  18307. } // END for CCS_QUANTITY
  18308. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18309. }
  18310. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18311. {
  18312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18313. {
  18314. tempIndex = ((gun_index==2) ? 1: 0);
  18315. }
  18316. else
  18317. {
  18318. tempIndex = gun_index;
  18319. }
  18320. for (int index = 0; index < GB_QUANTITY; index++)
  18321. {
  18322. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18323. {
  18324. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18325. }
  18326. }// END for GB_QUANTITY
  18327. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18328. }
  18329. else if(gunType[gun_index] == GUN_TYPE_DO)
  18330. {
  18331. tempIndex = gun_index;
  18332. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18333. {
  18334. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18335. {
  18336. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18337. }
  18338. }
  18339. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18340. }
  18341. else
  18342. {
  18343. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18344. {
  18345. tempIndex = 2;
  18346. }
  18347. else
  18348. {
  18349. tempIndex = gun_index;
  18350. }
  18351. for (int index = 0; index < AC_QUANTITY; index++)
  18352. {
  18353. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18354. {
  18355. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18356. }
  18357. } // END for AC_QUANTITY
  18358. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18359. }
  18360. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18361. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18362. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18363. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18364. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18365. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18366. }
  18367. //2.4====================================== Voltage L1 ====================================================
  18368. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18369. {
  18370. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18371. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18372. {
  18373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18374. {
  18375. tempIndex = ((gun_index==2) ? 1: 0);
  18376. }
  18377. else
  18378. {
  18379. tempIndex = gun_index;
  18380. }
  18381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18382. {
  18383. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18384. {
  18385. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18386. }
  18387. } // END OF FOR CHAdeMO_QUANTITY
  18388. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18389. }
  18390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18391. {
  18392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18393. {
  18394. tempIndex = ((gun_index==2) ? 1: 0);
  18395. }
  18396. else
  18397. {
  18398. tempIndex = gun_index;
  18399. }
  18400. for (int index = 0; index < CCS_QUANTITY; index++)
  18401. {
  18402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18403. {
  18404. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18405. }
  18406. } // END OF FOR CCS_QUANTITY
  18407. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18408. }
  18409. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18410. {
  18411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18412. {
  18413. tempIndex = ((gun_index==2) ? 1: 0);
  18414. }
  18415. else
  18416. {
  18417. tempIndex = gun_index;
  18418. }
  18419. for (int index = 0; index < GB_QUANTITY; index++)
  18420. {
  18421. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18422. {
  18423. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18424. }
  18425. } // END OF FOR GB_QUANTITY
  18426. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18427. }
  18428. else if(gunType[gun_index] == GUN_TYPE_DO)
  18429. {
  18430. tempIndex = gun_index;
  18431. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18432. {
  18433. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18434. {
  18435. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18436. }
  18437. }
  18438. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18439. }
  18440. else
  18441. {
  18442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18443. {
  18444. tempIndex = 2;
  18445. }
  18446. else
  18447. {
  18448. tempIndex = gun_index;
  18449. }
  18450. for (int index = 0; index < AC_QUANTITY; index++)
  18451. {
  18452. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18453. {
  18454. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  18455. }
  18456. } // END OF FOR AC_QUANTITY
  18457. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18458. }
  18459. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18460. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18461. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18462. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18463. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18464. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18465. }
  18466. //2.5============================================== End SoC =========================================================
  18467. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18468. {
  18469. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18470. 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))
  18471. {
  18472. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18473. {
  18474. tempIndex = ((gun_index==2) ? 1: 0);
  18475. }
  18476. else
  18477. {
  18478. tempIndex = gun_index;
  18479. }
  18480. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18481. {
  18482. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18483. {
  18484. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18485. {
  18486. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18487. }
  18488. }
  18489. }
  18490. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18491. {
  18492. for (int index = 0; index < CCS_QUANTITY; index++)
  18493. {
  18494. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18495. {
  18496. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18497. }
  18498. }
  18499. }
  18500. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18501. {
  18502. for (int index = 0; index < GB_QUANTITY; index++)
  18503. {
  18504. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18505. {
  18506. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18507. }
  18508. }
  18509. }
  18510. else if(gunType[gun_index] == GUN_TYPE_DO)
  18511. {
  18512. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18513. {
  18514. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18515. {
  18516. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18517. }
  18518. }
  18519. }
  18520. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18521. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18522. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18523. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18524. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18525. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18526. } // END FOR DC CASE
  18527. }
  18528. //2.6====================================== Current.Import L2 ==============================================
  18529. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18530. {
  18531. // AC 3 phase L2 current
  18532. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18533. {
  18534. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18535. {
  18536. tempIndex = 2;
  18537. }
  18538. else
  18539. {
  18540. tempIndex = gun_index;
  18541. }
  18542. for (int index = 0; index < AC_QUANTITY; index++)
  18543. {
  18544. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18545. {
  18546. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18547. }
  18548. }// End of for AC_QUANTITY
  18549. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18550. }
  18551. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18552. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18553. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18554. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18555. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18556. }
  18557. //2.7====================================== Current.Import L3 ==============================================
  18558. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18559. {
  18560. // AC 3 phase L3 current
  18561. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18562. {
  18563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18564. {
  18565. tempIndex = 2;
  18566. }
  18567. else
  18568. {
  18569. tempIndex = gun_index;
  18570. }
  18571. for (int index = 0; index < AC_QUANTITY; index++)
  18572. {
  18573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18574. {
  18575. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18576. }
  18577. }// End of for AC_QUANTITY
  18578. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18579. }
  18580. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18581. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18582. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18583. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18584. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18585. }
  18586. //2.9====================================== Voltage L2 ====================================================
  18587. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18588. {
  18589. // AC 3 phase L2 volatge
  18590. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18591. {
  18592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18593. {
  18594. tempIndex = 2;
  18595. }
  18596. else
  18597. {
  18598. tempIndex = gun_index;
  18599. }
  18600. for (int index = 0; index < AC_QUANTITY; index++)
  18601. {
  18602. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18603. {
  18604. 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
  18605. }
  18606. } // END OF FOR AC_QUANTITY
  18607. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18608. }
  18609. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18610. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18611. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18612. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18613. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18614. }
  18615. //2.10====================================== Voltage L3 ====================================================
  18616. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18617. {
  18618. // AC 3 phase L3 volatge
  18619. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18620. {
  18621. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18622. {
  18623. tempIndex = 2;
  18624. }
  18625. else
  18626. {
  18627. tempIndex = gun_index;
  18628. }
  18629. for (int index = 0; index < AC_QUANTITY; index++)
  18630. {
  18631. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18632. {
  18633. 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
  18634. }
  18635. } // END OF FOR AC_QUANTITY
  18636. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18637. }
  18638. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18639. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18640. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18641. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18642. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18643. }
  18644. //====================== Start SoC ================================
  18645. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18646. {
  18647. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18648. 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))
  18649. {
  18650. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18651. {
  18652. tempIndex = ((gun_index==2) ? 1: 0);
  18653. }
  18654. else
  18655. {
  18656. tempIndex = gun_index;
  18657. }
  18658. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18659. {
  18660. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18661. {
  18662. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18663. {
  18664. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18665. }
  18666. }
  18667. }
  18668. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18669. {
  18670. for (int index = 0; index < CCS_QUANTITY; index++)
  18671. {
  18672. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18673. {
  18674. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18675. }
  18676. }
  18677. }
  18678. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18679. {
  18680. for (int index = 0; index < GB_QUANTITY; index++)
  18681. {
  18682. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18683. {
  18684. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18685. }
  18686. }
  18687. }
  18688. else if(gunType[gun_index] == GUN_TYPE_DO)
  18689. {
  18690. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18691. {
  18692. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18693. {
  18694. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18695. }
  18696. }
  18697. }
  18698. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18699. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18700. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18701. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18702. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18703. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18704. } // END FOR DC CASE
  18705. }
  18706. //======================================== Message create ==============================================
  18707. json_object *StopTransaction = json_object_new_object();
  18708. json_object *transactionDatas = json_object_new_array();
  18709. json_object *sampledValues = json_object_new_array();
  18710. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  18711. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  18712. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  18713. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  18714. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  18715. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18716. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  18717. {
  18718. json_object *transactionData = json_object_new_object();
  18719. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18720. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18721. {
  18722. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18723. {
  18724. json_object *sampledValue = json_object_new_object();
  18725. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18726. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18727. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18728. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18729. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18730. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18731. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18732. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18733. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18734. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18735. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18736. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18737. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18738. json_object_array_add(sampledValues, sampledValue);
  18739. }
  18740. }
  18741. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18742. json_object_array_add(transactionDatas, transactionData);
  18743. }
  18744. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18745. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18746. ,MESSAGE_TYPE_CALL
  18747. ,guid
  18748. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18749. json_object_put(StopTransaction);
  18750. // Check File "TempStopTransaction" Exist
  18751. if((access(TempStopTransaction,F_OK))!=-1)
  18752. {
  18753. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18754. fclose(fopen(TempStopTransaction, "w"));
  18755. }
  18756. else
  18757. {
  18758. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18759. FILE *log = fopen(TempStopTransaction, "w+");
  18760. if(log == NULL)
  18761. {
  18762. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18763. return ;
  18764. }
  18765. else
  18766. {
  18767. fclose(log);
  18768. }
  18769. }
  18770. //Add TempStopTransaction | Update TempStopTransaction
  18771. // open file for writing
  18772. FILE *outfile;
  18773. outfile = fopen (TempStopTransaction, "a");
  18774. //DEBUG_INFO("data = %s\n", queuedata);
  18775. fputs(queuedata, outfile);
  18776. fputs("\n", outfile);
  18777. fclose (outfile);
  18778. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18779. }
  18780. void checkTempStopTransaction(int gun_index)
  18781. {
  18782. FILE *fptr1;
  18783. char ch;
  18784. char str[QUEUE_MESSAGE_LENGTH]={0};
  18785. char guid[37]={0};
  18786. char tempdata[65]={0};
  18787. char connectorStr[2]={0};
  18788. char TempStopTransaction[256];
  18789. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18790. fptr1 = fopen(TempStopTransaction, "r");
  18791. //TempStopTransaction格式: 槍號,StopTransaction封包
  18792. if (!fptr1)
  18793. {
  18794. //printf(" File not found or unable to open the input file!!\n");
  18795. return ;
  18796. }
  18797. ch=fgetc(fptr1);
  18798. //printf(" Now the content of the file %s is : \n",fname);
  18799. rewind(fptr1);
  18800. if(ch!=EOF)
  18801. {
  18802. // copy all contents to the temporary file except the specific line
  18803. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18804. {
  18805. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18806. if(str[0]=='\0')
  18807. {
  18808. break;
  18809. }
  18810. //TempStopTransaction格式: 槍號,StopTransaction封包
  18811. strncpy(connectorStr, str, 1);
  18812. if(atoi(connectorStr) != (gun_index+1))
  18813. {
  18814. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18815. fclose(fptr1);
  18816. return ;
  18817. }
  18818. //random_uuid(guid);
  18819. strncpy(guid, str+6, 36); //copy guid
  18820. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18821. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18822. {
  18823. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18824. }
  18825. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18826. OCPP_insert_transaction_msg(NO, str);
  18827. memset(str,0,ARRAY_SIZE(str));
  18828. }
  18829. }
  18830. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18831. fclose(fptr1);
  18832. remove(TempStopTransaction); // remove the original file
  18833. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18834. }
  18835. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18836. {
  18837. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18838. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18839. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18840. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18841. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18842. }
  18843. int GetWebSocketPingInterval(void)
  18844. {
  18845. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18846. }
  18847. int GetServerSign(void)
  18848. {
  18849. return server_sign;
  18850. }
  18851. uint8_t GetOcppSecurityProfile()
  18852. {
  18853. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18854. }
  18855. void GetOcppChargerBoxId(uint8_t *data)
  18856. {
  18857. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18858. }
  18859. void GetOcppSecurityPassword(uint8_t *data)
  18860. {
  18861. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18862. }
  18863. void SetOcppVersion(uint8_t *version)
  18864. {
  18865. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18866. DEBUG_INFO("ocpp version: %s\n", version);
  18867. if(strstr((char*)version, "ocpp1.6") != NULL)
  18868. {
  18869. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18870. }
  18871. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18872. {
  18873. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18874. system("pkill OcppBackend");
  18875. }
  18876. }
  18877. void SetServerSign(int value)
  18878. {
  18879. server_sign = value;
  18880. }
  18881. int GetBootNotificationInterval(void)
  18882. {
  18883. return BootNotificationInterval;
  18884. }
  18885. int GetInternetConn(void)
  18886. {
  18887. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18888. }
  18889. int GetBackendConnectionTimeout(void)
  18890. {
  18891. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18892. }
  18893. int isConnectorInitMode(int gun_index)
  18894. {
  18895. int tempIndex = 0;
  18896. int result = TRUE;
  18897. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18898. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18899. {
  18900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18901. {
  18902. tempIndex = ((gun_index==2) ? 1: 0);
  18903. }
  18904. else
  18905. {
  18906. tempIndex = gun_index;
  18907. }
  18908. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18909. {
  18910. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18911. {
  18912. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18913. } //end of the same index
  18914. }//end of for CHAdeMO_QUANTITY
  18915. }
  18916. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18917. {
  18918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18919. {
  18920. tempIndex = ((gun_index==2) ? 1: 0);
  18921. }
  18922. else
  18923. {
  18924. tempIndex = gun_index;
  18925. }
  18926. for (int index = 0; index < CCS_QUANTITY; index++)
  18927. {
  18928. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18929. {
  18930. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18931. } //end of the same index
  18932. } // end of for CCS_QUANTITY
  18933. }
  18934. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18935. {
  18936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18937. {
  18938. tempIndex = ((gun_index==2) ? 1: 0);
  18939. }
  18940. else
  18941. {
  18942. tempIndex = gun_index;
  18943. }
  18944. for (int index = 0; index < GB_QUANTITY; index++)
  18945. {
  18946. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18947. {
  18948. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18949. } //end of the same index
  18950. } // end of for GB_QUANTITY
  18951. }
  18952. else if(gunType[gun_index] == GUN_TYPE_DO)
  18953. {
  18954. tempIndex = gun_index;
  18955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18956. {
  18957. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18958. {
  18959. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18960. } //end of the same index
  18961. }
  18962. }
  18963. else
  18964. {
  18965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18966. {
  18967. tempIndex = 2;
  18968. }
  18969. else
  18970. {
  18971. tempIndex = gun_index;
  18972. }
  18973. for (int index = 0; index < AC_QUANTITY; index++)
  18974. {
  18975. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18976. {
  18977. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18978. }//end of the same index
  18979. }//end of for AC_QUANTITY
  18980. }
  18981. return result;
  18982. }
  18983. void refreshProcDogTimer()
  18984. {
  18985. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18986. }
  18987. void InitialSystemValue(void)
  18988. {
  18989. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18990. locallistVersion=0;
  18991. BootNotificationInterval = 0;
  18992. authorizeRetryTimes = 0;
  18993. GunStatusInterval = 10;
  18994. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18995. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18996. //Hear Beat
  18997. HeartBeatWithNOResponse = 0;
  18998. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18999. FirstHeartBeat = 0;
  19000. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  19001. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  19002. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19003. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19004. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19005. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19006. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19007. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19008. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19009. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19010. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19011. //Status && ConnectorPlugIn Setting
  19012. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19013. {
  19014. ChademoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19015. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19016. }
  19017. for (int index = 0; index < CCS_QUANTITY; index++)
  19018. {
  19019. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19020. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19021. }
  19022. for (int index = 0; index < GB_QUANTITY; index++)
  19023. {
  19024. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19025. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19026. }
  19027. for (int index = 0; index < AC_QUANTITY; index++)
  19028. {
  19029. AcPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19030. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19031. }
  19032. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19033. {
  19034. DoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19035. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19036. }
  19037. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19038. {
  19039. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  19040. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  19041. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  19042. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19043. //memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  19044. memset(&ShmOCPP16DataPH->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16DataPH->StatusNotification[gun_index].Status));
  19045. }
  19046. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  19047. refreshStartTimer(&clientTime.Heartbeat);
  19048. sleep(1);
  19049. }
  19050. void LWS_Send(char *str)
  19051. {
  19052. //=====================================================
  19053. // Check InternetConn 0: disconnected, 1: connected
  19054. //====================================================
  19055. if(GetOcppConnStatus() == 0)
  19056. {
  19057. DEBUG_INFO("offline now !!!\n");
  19058. return;
  19059. }
  19060. // Only disable isWebsocketSendable operation initiated by charger
  19061. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19062. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19063. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19064. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19065. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19066. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19067. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19068. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19069. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19070. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19071. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19072. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19073. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19074. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19075. {
  19076. isWebsocketSendable = 0;
  19077. }
  19078. pthread_mutex_lock(&lock_send);
  19079. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19080. sprintf((char *)SendBuffer, "%s", str);
  19081. SendBufLen = strlen(str);
  19082. pthread_mutex_unlock(&lock_send);
  19083. lws_callback_on_writable(wsi_client);
  19084. //lws_service(context, 0);
  19085. //sleep(1);
  19086. }
  19087. void LWS_SendNow(char *str)
  19088. {
  19089. //=====================================================
  19090. // Check InternetConn 0: disconnected, 1: connected
  19091. //====================================================
  19092. if(GetOcppConnStatus() == 0)
  19093. {
  19094. DEBUG_INFO("offline now !!!\n");
  19095. return;
  19096. }
  19097. // Only disable isWebsocketSendable operation initiated by charger
  19098. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19099. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19100. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19101. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19102. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19103. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19104. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19105. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19106. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19107. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19108. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19109. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19110. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19111. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19112. {
  19113. isWebsocketSendable = 0;
  19114. }
  19115. pthread_mutex_lock(&lock_send);
  19116. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19117. sprintf((char *)SendBuffer, "%s", str);
  19118. SendBufLen = strlen(str);
  19119. pthread_mutex_unlock(&lock_send);
  19120. lws_callback_on_writable(wsi_client);
  19121. lws_service(context, 0);
  19122. //sleep(1);
  19123. }