MessageHandler.c 958 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  56. //========================================
  57. // OCPP status/previous related variables
  58. //========================================
  59. static int GunStatusInterval = 10;
  60. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  61. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  62. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  63. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  64. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  65. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  66. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  67. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  68. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  69. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  70. static int TransactionMessageAttemptsValue = 0;
  71. static int TransactionMessageRetryIntervalValue = 0;
  72. static int TempMeterValueInterval = 0;
  73. static struct OCPPAuthLocalElemet
  74. {
  75. int listVersionInt;
  76. char idTagstr[21];
  77. char parentIdTag[21];
  78. char expiryDate[36];
  79. char idTagstatus[16];
  80. }idTagQuery;
  81. //============================================
  82. // OCPP MeterValue request flag
  83. //============================================
  84. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  85. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  86. //============================================
  87. // OCPP HeartBeat Response Not Receive Counts
  88. //============================================
  89. static int HeartBeatWithNOResponse = 0;
  90. //============================================
  91. // OCPP California Pricing Requirements
  92. //============================================
  93. static char dmsVersion[21] = {0};
  94. extern sqlite3 *db;
  95. int TransactionMessageAttemptsGet(void);
  96. int TransactionMessageRetryIntervalGet(void);
  97. int GetOcppConnStatus(void);
  98. void SetOcppConnStatus(uint8_t status);
  99. int setKeyValue(char *key, char *value);
  100. void OCPP_get_TableAuthlocalAllData(void);
  101. void processUnkownKey(void);
  102. struct InterLock
  103. {
  104. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  105. unsigned char isGetDiagnosticGoing:1;
  106. unsigned char isUpdateFirmwareGoing:1;
  107. }interLock;
  108. struct ClientTime
  109. {
  110. struct timespec Heartbeat;
  111. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  112. struct timespec StartTransaction;
  113. struct timespec StopTransaction;
  114. struct timespec MeterValues[CONNECTOR_QUANTITY];
  115. struct timespec RemoteStartWait;
  116. struct timespec TcciQueryDeduct;
  117. }clientTime;
  118. typedef union
  119. {
  120. //Operations Initiated by Central System
  121. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  122. struct
  123. {
  124. //CsMsgValue[0]
  125. unsigned char StatusNotificationReq:1; //bit 0,
  126. unsigned char StatusNotificationConf:1; //bit 1,
  127. unsigned char TriggerMeterValue:1; //bit 2,
  128. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  129. unsigned char isOnCharging:1; //bit 4.
  130. unsigned char :3; //bit 5~7
  131. }bits[CONNECTOR_QUANTITY];
  132. }CpinitiateMsg;
  133. CpinitiateMsg cpinitateMsg;
  134. //GetConfiguration Array
  135. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  136. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  137. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  138. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  139. static char *ChargePointErrorCodeStr[] = {
  140. MACROSTR(ConnectorLockFailure),
  141. MACROSTR(EVCommunicationError),
  142. MACROSTR(GroundFailure),
  143. MACROSTR(HighTemperature),
  144. MACROSTR(InternalError),
  145. MACROSTR(LocalListConflict),
  146. MACROSTR(NoError),
  147. MACROSTR(OtherError),
  148. MACROSTR(OverCurrentFailure),
  149. MACROSTR(OverVoltage),
  150. MACROSTR(PowerMeterFailure),
  151. MACROSTR(PowerSwitchFailure),
  152. MACROSTR(ReaderFailure),
  153. MACROSTR(ResetFailure),
  154. MACROSTR(UnderVoltage),
  155. MACROSTR(WeakSignal)
  156. };
  157. static char * ChargePointStatusStr[] = {
  158. MACROSTR(Available),
  159. MACROSTR(Preparing),
  160. MACROSTR(Charging),
  161. MACROSTR(SuspendedEVSE),
  162. MACROSTR(SuspendedEV),
  163. MACROSTR(Finishing),
  164. MACROSTR(Reserved),
  165. MACROSTR(Unavailable),
  166. MACROSTR(Faulted)
  167. };
  168. static char *RegistrationStatusStr[] = {
  169. MACROSTR(Accepted),
  170. MACROSTR(Pending),
  171. MACROSTR(Rejected)
  172. };
  173. static char *AvailabilityTypeStr[] = {
  174. MACROSTR(Inoperative),
  175. MACROSTR(Operative)
  176. };
  177. static char *AvailabilityStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(Scheduled)
  181. };
  182. static char *ConfigurationStatusStr[] = {
  183. MACROSTR(Accepted),
  184. MACROSTR(Rejected),
  185. MACROSTR(RebootRequired),
  186. MACROSTR(NotSupported)
  187. };
  188. static char *ClearCacheStatusStr[] = {
  189. MACROSTR(Accepted),
  190. MACROSTR(Rejected)
  191. };
  192. static char *ChargingProfilePurposeTypeStr[] = {
  193. MACROSTR(ChargePointMaxProfile),
  194. MACROSTR(TxDefaultProfile),
  195. MACROSTR(TxProfile)
  196. };
  197. static char *ChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Rejected),
  200. MACROSTR(NotSupported)
  201. };
  202. static char *ClearChargingProfileStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Unknown)
  205. };
  206. static char *GetCompositeScheduleStatusStr[] = {
  207. MACROSTR(Accepted),
  208. MACROSTR(Rejected)
  209. };
  210. static char *UpdateTypeStr[] = {
  211. MACROSTR(Differential),
  212. MACROSTR(Full)
  213. };
  214. static char *UpdateStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Failed),
  217. MACROSTR(NotSupported),
  218. MACROSTR(VersionMismatch)
  219. };
  220. static char *RemoteStartStopStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Rejected)
  223. };
  224. static char *ReservationStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Faulted),
  227. MACROSTR(Occupied),
  228. MACROSTR(Rejected),
  229. MACROSTR(Unavailable)
  230. };
  231. static char *ResetTypeStr[] = {
  232. MACROSTR(Hard),
  233. MACROSTR(Soft)
  234. };
  235. static char *ResetStatusStr[] = {
  236. MACROSTR(Accepted),
  237. MACROSTR(Rejected)
  238. };
  239. static char * DiagnosticsStatusStr[] = {
  240. MACROSTR(Idle),
  241. MACROSTR(Uploaded),
  242. MACROSTR(UploadFailed),
  243. MACROSTR(Uploading)
  244. };
  245. static char * FirmwareStatusStr[] = {
  246. MACROSTR(Downloaded),
  247. MACROSTR(DownloadFailed),
  248. MACROSTR(Downloading),
  249. MACROSTR(Idle),
  250. MACROSTR(InstallationFailed),
  251. MACROSTR(Installing),
  252. MACROSTR(Installed)
  253. };
  254. static char * MessageTriggerStr[] = {
  255. MACROSTR(BootNotification),
  256. MACROSTR(DiagnosticsStatusNotification),
  257. MACROSTR(FirmwareStatusNotification),
  258. MACROSTR(Heartbeat),
  259. MACROSTR(MeterValues),
  260. MACROSTR(StatusNotification)
  261. };
  262. static char * TriggerMessageStatusStr[] = {
  263. MACROSTR(Accepted),
  264. MACROSTR(Rejected),
  265. MACROSTR(NotImplemented)
  266. };
  267. static char * UnlockStatusStr[] = {
  268. MACROSTR(Unlocked),
  269. MACROSTR(UnlockFailed),
  270. MACROSTR(NotSupported)
  271. };
  272. #if 0
  273. static char * StopTransactionReasonStr[] = {
  274. MACROSTR(EmergencyStop),
  275. MACROSTR(EVDisconnected),
  276. MACROSTR(HardReset),
  277. MACROSTR(Local),
  278. MACROSTR(Other),
  279. MACROSTR(PowerLoss),
  280. MACROSTR(Reboot),
  281. MACROSTR(Remote),
  282. MACROSTR(SoftReset),
  283. MACROSTR(UnlockCommand),
  284. MACROSTR(DeAuthorized)
  285. };
  286. #endif
  287. static char * CancelReservationStatusStr[] = {
  288. MACROSTR(Accepted),
  289. MACROSTR(Rejected)
  290. };
  291. static char * ReadingContextStr[] = {
  292. MACROSTR(Interruption.Begin),
  293. MACROSTR(Interruption.End),
  294. MACROSTR(Other),
  295. MACROSTR(Sample.Clock),
  296. MACROSTR(Sample.Periodic),
  297. MACROSTR(Transaction.Begin),
  298. MACROSTR(Transaction.End),
  299. MACROSTR(Trigger)
  300. };
  301. static char * ValueFormatStr[] = {
  302. MACROSTR(Raw),
  303. MACROSTR(SignedData)
  304. };
  305. static char * MeasurandStr[] = {
  306. MACROSTR(Current.Export),
  307. MACROSTR(Current.Import),
  308. MACROSTR(Current.Offered),
  309. MACROSTR(Energy.Active.Export.Register),
  310. MACROSTR(Energy.Active.Import.Register),
  311. MACROSTR(Energy.Reactive.Export.Register),
  312. MACROSTR(Energy.Reactive.Import.Register),
  313. MACROSTR(Energy.Active.Export.Interval),
  314. MACROSTR(Energy.Active.Import.Interval),
  315. MACROSTR(Energy.Reactive.Export.Interval),
  316. MACROSTR(Energy.Reactive.Import.Interval),
  317. MACROSTR(Frequency),
  318. MACROSTR(Power.Active.Export),
  319. MACROSTR(Power.Active.Import),
  320. MACROSTR(Power.Factor),
  321. MACROSTR(Power.Offered),
  322. MACROSTR(Power.Reactive.ExportMACROSTR),
  323. MACROSTR(Power.Reactive.Import),
  324. MACROSTR(RPM),
  325. MACROSTR(SoC),
  326. MACROSTR(Temperature),
  327. MACROSTR(Voltage)
  328. };
  329. static char * LocationStr[] = {
  330. MACROSTR(Body),
  331. MACROSTR(Cable),
  332. MACROSTR(EV),
  333. MACROSTR(Inlet),
  334. MACROSTR(Outlet)
  335. };
  336. static char * PhaseStr[] = {
  337. MACROSTR(L1),
  338. MACROSTR(L2),
  339. MACROSTR(L3),
  340. MACROSTR(N),
  341. MACROSTR(L1-N),
  342. MACROSTR(L2-N),
  343. MACROSTR(L3-N),
  344. MACROSTR(L1-L2),
  345. MACROSTR(L2-L3),
  346. MACROSTR(L3-L1)
  347. };
  348. static char * UnitOfMeasureStr[] = {
  349. MACROSTR(Wh),
  350. MACROSTR(kWh),
  351. MACROSTR(varh),
  352. MACROSTR(kvarh),
  353. MACROSTR(W),
  354. MACROSTR(kW),
  355. MACROSTR(VA),
  356. MACROSTR(kVA),
  357. MACROSTR(var),
  358. MACROSTR(kvar),
  359. MACROSTR(A),
  360. MACROSTR(V),
  361. MACROSTR(Celsius),
  362. MACROSTR(Fahrenheit),
  363. MACROSTR(K),
  364. MACROSTR(Percent)
  365. };
  366. //=========================================
  367. // Save configuration
  368. //=========================================
  369. int runShellCmd(const char*cmd)
  370. {
  371. int result = FAIL;
  372. char buf[256];
  373. FILE *fp;
  374. fp = popen(cmd, "r");
  375. if(fp != NULL)
  376. {
  377. while(fgets(buf, sizeof(buf), fp) != NULL)
  378. {
  379. DEBUG_INFO("%s\n", buf);
  380. }
  381. result = PASS;
  382. }
  383. pclose(fp);
  384. return result;
  385. }
  386. int StoreUsrConfigData(struct SysConfigData *UsrData)
  387. {
  388. int result = PASS;
  389. int fd,wrd;
  390. unsigned int i,Chk;
  391. unsigned char *ptr, *BufTmp;
  392. int MtdBlockSize = 0x300000;
  393. Chk=0;
  394. ptr=(unsigned char *)UsrData;
  395. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  396. {
  397. memset(BufTmp,0,MtdBlockSize);
  398. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  399. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  400. Chk+=*(BufTmp+i);
  401. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  402. // Output configuration to file.
  403. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  404. if (fd < 0)
  405. {
  406. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  407. free(BufTmp);
  408. return 0;
  409. }
  410. wrd=write(fd, BufTmp, MtdBlockSize);
  411. close(fd);
  412. if(wrd<MtdBlockSize)
  413. {
  414. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  415. free(BufTmp);
  416. return 0;
  417. }
  418. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  419. DEBUG_INFO("Erase /dev/mtd10.\n");
  420. runShellCmd("flash_erase /dev/mtd10 0 0");
  421. DEBUG_INFO("Write /dev/mtd10.\n");
  422. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  423. DEBUG_INFO("Erase /dev/mtd11.\n");
  424. runShellCmd("flash_erase /dev/mtd11 0 0");
  425. DEBUG_INFO("Write /dev/mtd11.\n");
  426. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  427. system("rm -f /mnt/EvseConfig.bin");
  428. DEBUG_INFO("EvseConfig write to flash OK\n");
  429. }
  430. else
  431. {
  432. DEBUG_ERROR("alloc BlockSize NG\r\n");
  433. result = FAIL;
  434. }
  435. if(BufTmp!=NULL)
  436. free(BufTmp);
  437. return result;
  438. }
  439. //=========================================
  440. // Sqlite3 related function
  441. //=========================================
  442. static int selectSqlCount = 0;
  443. static int callback(void *data, int argc, char **argv, char **azColName){
  444. int i;
  445. //printf("%s: ", (const char*)data);
  446. selectSqlCount = argc;
  447. for(i = 0; i<argc; i++){
  448. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  449. }
  450. //printf("\n");
  451. return 0;
  452. }
  453. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  454. //int i;
  455. //printf("%s:\n", (const char*)data);
  456. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  457. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  458. return 0;
  459. }
  460. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  461. //printf("%s:\n", (const char*)data);
  462. //idTag
  463. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  464. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  465. //parentIdTag
  466. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  467. //expir_date
  468. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  469. //status
  470. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  471. //version
  472. if(columenCount > 5)
  473. idTagQuery.listVersionInt = atoi(columnValue[5]);
  474. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  475. return 0;
  476. }
  477. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  478. {
  479. // localversion = argv[5] ? atoi(argv[5]) : 0;
  480. // printf("localversion=%d\n", localversion);
  481. return 0;
  482. }
  483. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  484. {
  485. for (int i = 0; i < n_columns; i++)
  486. {
  487. DEBUG_INFO("%s\t", col_values[i]);
  488. }
  489. DEBUG_INFO("\n");
  490. return 0;
  491. }
  492. int OCPP_cleanLocalCache()
  493. {
  494. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  495. char *errMsg = 0;
  496. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  497. if (SQLITE_OK != rc)
  498. {
  499. DEBUG_INFO("SQL error: %s\n",errMsg);
  500. return FALSE;
  501. }
  502. return TRUE;
  503. }
  504. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  505. {
  506. int isSuccess = TRUE;
  507. int ret = 0;
  508. //const char* data = "Callback function called";
  509. char sql[300];
  510. char zErrMsg[200];
  511. memset(sql, 0, 300);
  512. memset(zErrMsg, 0, 200);
  513. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  514. //* Execute SQL statement */
  515. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  516. if( ret != SQLITE_OK )
  517. {
  518. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  519. isSuccess = FALSE;
  520. }
  521. return isSuccess;
  522. }
  523. void OCPP_getIdTagFromLocalCache(char idTag[])
  524. {
  525. int rc = 0;
  526. char sql[100];
  527. char zErrMsg[100];
  528. memset(sql, 0, 100);
  529. memset(zErrMsg, 0, 100);
  530. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  531. memset(&idTagQuery, 0, sizeof(idTagQuery));
  532. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  533. /* Execute SQL statement */
  534. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  535. if( rc != SQLITE_OK )
  536. {
  537. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  538. }
  539. }
  540. void OCPP_getListVerion()
  541. {
  542. int rc = 0;
  543. // const char* data = "Callback function called";
  544. char sql[100];
  545. char zErrMsg[100];
  546. memset(sql, 0, 100);
  547. memset(zErrMsg, 0, 100);
  548. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  549. /* Execute SQL statement */
  550. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  551. if( rc != SQLITE_OK )
  552. {
  553. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  554. }
  555. }
  556. void OCPP_get_TableAuthlocalAllData(void)
  557. {
  558. int rc = 0;
  559. char sql[100];
  560. char zErrMsg[100];
  561. memset(sql, 0, 100);
  562. memset(zErrMsg, 0, 100);
  563. sprintf(sql,"select * from ocpp_auth_local ");
  564. /* Execute SQL statement */
  565. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  566. if( rc != SQLITE_OK )
  567. {
  568. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  569. }
  570. //return ver;
  571. }
  572. int OCPP_cleanLocalList()
  573. {
  574. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  575. char *errMsg = 0;
  576. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  577. if (SQLITE_OK != rc)
  578. {
  579. DEBUG_INFO("%s\n",errMsg);
  580. return FALSE;
  581. }
  582. return TRUE;
  583. }
  584. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  585. {
  586. int isSuccess = FALSE;
  587. int ret = 0;
  588. //const char* data = "Callback function called";
  589. char sql[300];
  590. char zErrMsg[200];
  591. memset(sql, 0, 300);
  592. memset(zErrMsg, 0, 200);
  593. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  594. //* Execute SQL statement */
  595. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  596. if( ret != SQLITE_OK )
  597. {
  598. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  599. return isSuccess;
  600. }
  601. memset(sql, 0, 300);
  602. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  603. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  604. if( ret != SQLITE_OK )
  605. {
  606. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  607. return isSuccess;
  608. }
  609. isSuccess = TRUE;
  610. return isSuccess;
  611. }
  612. void OCPP_getIdTagFromLocalList(char idTag[])
  613. {
  614. int rc = 0;
  615. // const char* data = "Callback function called";
  616. char sql[100];
  617. char zErrMsg[100];
  618. memset(sql, 0, 100);
  619. memset(zErrMsg, 0, 100);
  620. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  621. memset(&idTagQuery, 0, sizeof(idTagQuery));
  622. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  623. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  624. /* Execute SQL statement */
  625. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  626. if( rc != SQLITE_OK )
  627. {
  628. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  629. }
  630. //return ver;
  631. }
  632. void OCPP_deleteIdTagFromLocalList(char idTag[])
  633. {
  634. //int ver = 0;
  635. //int isSuccess = FALSE;
  636. int rc = 0;
  637. char sql[100];
  638. char zErrMsg[100];
  639. memset(sql, 0, 100);
  640. memset(zErrMsg, 0, 100);
  641. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  642. //* Execute SQL statement */
  643. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  644. if( rc != SQLITE_OK )
  645. {
  646. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  647. }
  648. }
  649. int getCurrentYear()
  650. {
  651. int result = 0;
  652. time_t CurrentTime;
  653. struct tm *tm;
  654. CurrentTime = time(NULL);
  655. tm=localtime(&CurrentTime);
  656. result = (tm->tm_year + 1900);
  657. return result;
  658. }
  659. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  660. {
  661. int result = PASS;
  662. char* errMsg = NULL;
  663. char sqlStr[8192];
  664. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  665. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  666. {
  667. result = FAIL;
  668. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  669. }
  670. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  671. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  672. {
  673. result = FAIL;
  674. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  675. }
  676. return result;
  677. }
  678. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  679. {
  680. int result = PASS;
  681. char* errMsg = NULL;
  682. char sqlStr[8192];
  683. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  684. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  685. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  686. {
  687. result = FAIL;
  688. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  689. }
  690. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  691. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  692. {
  693. result = FAIL;
  694. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  695. }
  696. return result;
  697. }
  698. int OCPP_update_deduct_info(int txId, char *creditNo)
  699. {
  700. int result = PASS;
  701. char* errMsg = NULL;
  702. char sqlStr[8192];
  703. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  704. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  705. {
  706. result = FAIL;
  707. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  708. }
  709. return result;
  710. }
  711. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  712. {
  713. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  714. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  715. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  716. atoi(columnValue[1]),
  717. columnValue[2],
  718. atoi(columnValue[3])==1?"true":"false",
  719. atoi(columnValue[4])==1?"true":"false",
  720. columnValue[5],
  721. columnValue[9]);
  722. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  723. return 0;
  724. }
  725. void OCPP_query_deduct_info()
  726. {
  727. int rc = 0;
  728. char sql[100];
  729. char zErrMsg[100];
  730. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  731. /* Execute SQL statement */
  732. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  733. if( rc != SQLITE_OK )
  734. {
  735. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  736. }
  737. }
  738. void reportReaderStatus(int gun_index)
  739. {
  740. struct timeval tmnow;
  741. struct tm *tm;
  742. char buf[28];//, usec_buf[6];
  743. gettimeofday(&tmnow, NULL);
  744. time_t t;
  745. t = time(NULL);
  746. /*UTC time and date*/
  747. tm = gmtime(&t);
  748. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  749. #if 0 // remove temporally
  750. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  751. strcat(buf,".");
  752. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  753. strcat(buf,usec_buf);
  754. #endif
  755. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  756. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  757. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  758. (gun_index+1),
  759. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  760. buf,
  761. ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index],
  762. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].creditNo,
  763. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  764. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  765. }
  766. //==========================================
  767. // Check time passed since today
  768. //==========================================
  769. long long DiffTimebWithNow(struct timeb ST)
  770. {
  771. //return milli-second
  772. struct timeb ET;
  773. long long StartTime,StopTime;
  774. ftime(&ET);
  775. StartTime=(long long)ST.time;
  776. StopTime=(long long)ET.time;
  777. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  778. }
  779. int getTimePassSinceToday(uint8_t gun_index)
  780. {
  781. int result = -1;
  782. static time_t lastTime[4];
  783. time_t t;
  784. struct tm *tmStartToday;
  785. struct timeb tbStartToday;
  786. t=time(NULL);
  787. if(difftime(t, lastTime[gun_index])>0)
  788. {
  789. tmStartToday=localtime(&t);
  790. tmStartToday->tm_hour = 0;
  791. tmStartToday->tm_min = 0;
  792. tmStartToday->tm_sec = 0;
  793. tbStartToday.time = mktime(tmStartToday);
  794. tbStartToday.millitm = 0;
  795. result = DiffTimebWithNow(tbStartToday)/1000;
  796. lastTime[gun_index] = t;
  797. }
  798. return result;
  799. }
  800. void getNowDatetime(uint8_t *data)
  801. {
  802. time_t t = time(NULL);
  803. struct tm tm = *localtime(&t);
  804. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  805. }
  806. int syncDateTimeRTC(uint8_t *data)
  807. {
  808. struct ParsingResult
  809. {
  810. int result;
  811. int scanedElement;
  812. int year;
  813. int month;
  814. int mday;
  815. int hour;
  816. int min;
  817. int sec;
  818. int tz_hour;
  819. int tz_min;
  820. float minSec;
  821. }result;
  822. struct tm tmOrg;
  823. struct tm *tmTarget;
  824. struct timeb tbTarget;
  825. char buf[128];
  826. memset(&result, 0x00, sizeof(struct ParsingResult));
  827. result.result = PASS;
  828. if(strstr((char*)data, ".") != NULL)
  829. {
  830. // Original data with mini second
  831. if(strstr((char*)data, "Z") != NULL)
  832. {
  833. // Original data with Z
  834. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  835. &result.year,
  836. &result.month,
  837. &result.mday,
  838. &result.hour,
  839. &result.min,
  840. &result.sec,
  841. &result.minSec);
  842. }
  843. else
  844. {
  845. // Original data without Z
  846. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  847. &result.year,
  848. &result.month,
  849. &result.mday,
  850. &result.hour,
  851. &result.min,
  852. &result.sec,
  853. &result.minSec,
  854. &result.tz_hour,
  855. &result.tz_min);
  856. }
  857. }
  858. else
  859. {
  860. // Original data without mini second
  861. if(strstr((char*)data, "Z") != NULL)
  862. {
  863. // Original data with Z
  864. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  865. &result.year,
  866. &result.month,
  867. &result.mday,
  868. &result.hour,
  869. &result.min,
  870. &result.sec);
  871. }
  872. else
  873. {
  874. // Original data without Z
  875. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  876. &result.year,
  877. &result.month,
  878. &result.mday,
  879. &result.hour,
  880. &result.min,
  881. &result.sec,
  882. &result.tz_hour,
  883. &result.tz_min);
  884. }
  885. }
  886. tmOrg.tm_year = result.year - 1900;
  887. tmOrg.tm_mon = result.month - 1;
  888. tmOrg.tm_mday = result.mday;
  889. tmOrg.tm_hour = result.hour;
  890. tmOrg.tm_min = result.min;
  891. tmOrg.tm_sec = result.sec;
  892. tmOrg.tm_gmtoff = 0;
  893. tbTarget.time = mktime(&tmOrg);
  894. tbTarget.timezone = 0;
  895. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  896. tmTarget = gmtime(&tbTarget.time);
  897. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  898. //DEBUG_INFO(" org date time: %s\n", data);
  899. //DEBUG_INFO("parse date time: %s\n", buf);
  900. system(buf);
  901. system("/sbin/hwclock -w --systohc");
  902. if(result.scanedElement < 6)
  903. result.result = FAIL;
  904. return result.result;
  905. }
  906. //==========================================
  907. // GetCompositeSchedule logic related function
  908. //==========================================
  909. int DiffTimebSec(struct timeb ST, struct timeb ET)
  910. {
  911. //return milli-second
  912. unsigned int StartTime,StopTime;
  913. StartTime=(unsigned int)ST.time;
  914. StopTime=(unsigned int)ET.time;
  915. return (StopTime-StartTime);
  916. }
  917. int DiffTimebWithNowSec(struct timeb ST)
  918. {
  919. //return milli-second
  920. struct timeb ET;
  921. unsigned int StartTime,StopTime;
  922. ftime(&ET);
  923. StartTime=(unsigned int)ST.time;
  924. StopTime=(unsigned int)ET.time;
  925. return (StopTime-StartTime);
  926. }
  927. int getStartStop(uint8_t *start, uint8_t *stop)
  928. {
  929. struct ParsingResult
  930. {
  931. int result;
  932. int scanedElement;
  933. int year;
  934. int month;
  935. int mday;
  936. int hour;
  937. int min;
  938. int sec;
  939. int tz_hour;
  940. int tz_min;
  941. float minSec;
  942. };
  943. struct ParsingResult parseStart;
  944. struct ParsingResult parseStop;
  945. int result = -1;
  946. struct tm tmStart;
  947. struct timeb tbStart;
  948. struct tm tmStop;
  949. struct timeb tbStop;
  950. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  951. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  952. // Scan start & stop date time
  953. if(strstr((char*)start, ".") != NULL)
  954. {
  955. // Original data with mini second
  956. if(strstr((char*)start, "Z") != NULL)
  957. {
  958. // Original data with Z
  959. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  960. &parseStart.year,
  961. &parseStart.month,
  962. &parseStart.mday,
  963. &parseStart.hour,
  964. &parseStart.min,
  965. &parseStart.sec,
  966. &parseStart.minSec);
  967. }
  968. else
  969. {
  970. // Original data without Z
  971. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  972. &parseStart.year,
  973. &parseStart.month,
  974. &parseStart.mday,
  975. &parseStart.hour,
  976. &parseStart.min,
  977. &parseStart.sec,
  978. &parseStart.minSec,
  979. &parseStart.tz_hour,
  980. &parseStart.tz_min);
  981. }
  982. }
  983. else
  984. {
  985. // Original data without mini second
  986. if(strstr((char*)start, "Z") != NULL)
  987. {
  988. // Original data with Z
  989. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  990. &parseStart.year,
  991. &parseStart.month,
  992. &parseStart.mday,
  993. &parseStart.hour,
  994. &parseStart.min,
  995. &parseStart.sec);
  996. }
  997. else
  998. {
  999. // Original data without Z
  1000. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1001. &parseStart.year,
  1002. &parseStart.month,
  1003. &parseStart.mday,
  1004. &parseStart.hour,
  1005. &parseStart.min,
  1006. &parseStart.sec,
  1007. &parseStart.tz_hour,
  1008. &parseStart.tz_min);
  1009. }
  1010. }
  1011. if(strstr((char*)stop, ".") != NULL)
  1012. {
  1013. // Original data with mini second
  1014. if(strstr((char*)stop, "Z") != NULL)
  1015. {
  1016. // Original data with Z
  1017. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1018. &parseStop.year,
  1019. &parseStop.month,
  1020. &parseStop.mday,
  1021. &parseStop.hour,
  1022. &parseStop.min,
  1023. &parseStop.sec,
  1024. &parseStop.minSec);
  1025. }
  1026. else
  1027. {
  1028. // Original data without Z
  1029. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1030. &parseStop.year,
  1031. &parseStop.month,
  1032. &parseStop.mday,
  1033. &parseStop.hour,
  1034. &parseStop.min,
  1035. &parseStop.sec,
  1036. &parseStop.minSec,
  1037. &parseStop.tz_hour,
  1038. &parseStop.tz_min);
  1039. }
  1040. }
  1041. else
  1042. {
  1043. // Original data without mini second
  1044. if(strstr((char*)stop, "Z") != NULL)
  1045. {
  1046. // Original data with Z
  1047. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1048. &parseStop.year,
  1049. &parseStop.month,
  1050. &parseStop.mday,
  1051. &parseStop.hour,
  1052. &parseStop.min,
  1053. &parseStop.sec);
  1054. }
  1055. else
  1056. {
  1057. // Original data without Z
  1058. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1059. &parseStop.year,
  1060. &parseStop.month,
  1061. &parseStop.mday,
  1062. &parseStop.hour,
  1063. &parseStop.min,
  1064. &parseStop.sec,
  1065. &parseStop.tz_hour,
  1066. &parseStop.tz_min);
  1067. }
  1068. }
  1069. // Calculate date time difference
  1070. if((parseStart.scanedElement >=6) &&
  1071. (parseStop.scanedElement >=6))
  1072. {
  1073. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1074. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1075. tmStart.tm_year = parseStart.year - 1900;
  1076. tmStart.tm_mon = parseStart.month - 1;
  1077. tmStart.tm_mday = parseStart.mday;
  1078. tmStart.tm_hour = parseStart.hour;
  1079. tmStart.tm_min = parseStart.min;
  1080. tmStart.tm_sec = parseStart.sec;
  1081. tmStart.tm_gmtoff = 0;
  1082. tbStart.time = mktime(&tmStart);
  1083. tbStart.timezone = 0;
  1084. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1085. tmStop.tm_year = parseStop.year - 1900;
  1086. tmStop.tm_mon = parseStop.month - 1;
  1087. tmStop.tm_mday = parseStop.mday;
  1088. tmStop.tm_hour = parseStop.hour;
  1089. tmStop.tm_min = parseStop.min;
  1090. tmStop.tm_sec = parseStop.sec;
  1091. tmStop.tm_gmtoff = 0;
  1092. tbStop.time = mktime(&tmStop);
  1093. tbStop.timezone = 0;
  1094. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1095. result = DiffTimebSec(tbStart, tbStop);
  1096. //DEBUG_INFO("getStartStop(): %d\n", result);
  1097. }
  1098. else
  1099. {
  1100. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1101. }
  1102. return result;
  1103. }
  1104. int isOvertNow(uint8_t *start)
  1105. {
  1106. int result = NO;
  1107. struct ParsingResult
  1108. {
  1109. int result;
  1110. int scanedElement;
  1111. int year;
  1112. int month;
  1113. int mday;
  1114. int hour;
  1115. int min;
  1116. int sec;
  1117. int tz_hour;
  1118. int tz_min;
  1119. float minSec;
  1120. }parsingResult;
  1121. struct tm tmStart;
  1122. struct timeb tbStart;
  1123. if(strstr((char*)start, ".") != NULL)
  1124. {
  1125. // Original data with mini second
  1126. if(strstr((char*)start, "Z") != NULL)
  1127. {
  1128. // Original data with Z
  1129. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1130. &parsingResult.year,
  1131. &parsingResult.month,
  1132. &parsingResult.mday,
  1133. &parsingResult.hour,
  1134. &parsingResult.min,
  1135. &parsingResult.sec,
  1136. &parsingResult.minSec);
  1137. }
  1138. else
  1139. {
  1140. // Original data without Z
  1141. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1142. &parsingResult.year,
  1143. &parsingResult.month,
  1144. &parsingResult.mday,
  1145. &parsingResult.hour,
  1146. &parsingResult.min,
  1147. &parsingResult.sec,
  1148. &parsingResult.minSec,
  1149. &parsingResult.tz_hour,
  1150. &parsingResult.tz_min);
  1151. }
  1152. }
  1153. else
  1154. {
  1155. // Original data without mini second
  1156. if(strstr((char*)start, "Z") != NULL)
  1157. {
  1158. // Original data with Z
  1159. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1160. &parsingResult.year,
  1161. &parsingResult.month,
  1162. &parsingResult.mday,
  1163. &parsingResult.hour,
  1164. &parsingResult.min,
  1165. &parsingResult.sec);
  1166. }
  1167. else
  1168. {
  1169. // Original data without Z
  1170. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1171. &parsingResult.year,
  1172. &parsingResult.month,
  1173. &parsingResult.mday,
  1174. &parsingResult.hour,
  1175. &parsingResult.min,
  1176. &parsingResult.sec,
  1177. &parsingResult.tz_hour,
  1178. &parsingResult.tz_min);
  1179. }
  1180. }
  1181. if(parsingResult.scanedElement >= 6)
  1182. {
  1183. tmStart.tm_year = parsingResult.year - 1900;
  1184. tmStart.tm_mon = parsingResult.month - 1;
  1185. tmStart.tm_mday = parsingResult.mday;
  1186. tmStart.tm_hour = parsingResult.hour;
  1187. tmStart.tm_min = parsingResult.min;
  1188. tmStart.tm_sec = parsingResult.sec;
  1189. tmStart.tm_gmtoff = 0;
  1190. tbStart.time = mktime(&tmStart);
  1191. tbStart.timezone = 0;
  1192. tbStart.millitm = 0;
  1193. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1194. if(DiffTimebWithNowSec(tbStart) <= 0)
  1195. result = NO;
  1196. else
  1197. result = YES;
  1198. }
  1199. else
  1200. {
  1201. DEBUG_WARN("Start date parsing error.\n");
  1202. }
  1203. return result;
  1204. }
  1205. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1206. {
  1207. struct ParsingResult
  1208. {
  1209. int result;
  1210. int scanedElement;
  1211. int year;
  1212. int month;
  1213. int mday;
  1214. int hour;
  1215. int min;
  1216. int sec;
  1217. int tz_hour;
  1218. int tz_min;
  1219. float minSec;
  1220. };
  1221. struct ParsingResult parseStart;
  1222. struct ParsingResult parseStop;
  1223. int result = -1;
  1224. struct tm tmStart;
  1225. struct timeb tbStart;
  1226. struct tm tmStop;
  1227. struct timeb tbStop;
  1228. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1229. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1230. // Scan start & stop date time
  1231. if(strstr((char*)start, ".") != NULL)
  1232. {
  1233. // Original data with mini second
  1234. if(strstr((char*)start, "Z") != NULL)
  1235. {
  1236. // Original data with Z
  1237. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1238. &parseStart.year,
  1239. &parseStart.month,
  1240. &parseStart.mday,
  1241. &parseStart.hour,
  1242. &parseStart.min,
  1243. &parseStart.sec,
  1244. &parseStart.minSec);
  1245. }
  1246. else
  1247. {
  1248. // Original data without Z
  1249. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1250. &parseStart.year,
  1251. &parseStart.month,
  1252. &parseStart.mday,
  1253. &parseStart.hour,
  1254. &parseStart.min,
  1255. &parseStart.sec,
  1256. &parseStart.minSec,
  1257. &parseStart.tz_hour,
  1258. &parseStart.tz_min);
  1259. }
  1260. }
  1261. else
  1262. {
  1263. // Original data without mini second
  1264. if(strstr((char*)start, "Z") != NULL)
  1265. {
  1266. // Original data with Z
  1267. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1268. &parseStart.year,
  1269. &parseStart.month,
  1270. &parseStart.mday,
  1271. &parseStart.hour,
  1272. &parseStart.min,
  1273. &parseStart.sec);
  1274. }
  1275. else
  1276. {
  1277. // Original data without Z
  1278. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1279. &parseStart.year,
  1280. &parseStart.month,
  1281. &parseStart.mday,
  1282. &parseStart.hour,
  1283. &parseStart.min,
  1284. &parseStart.sec,
  1285. &parseStart.tz_hour,
  1286. &parseStart.tz_min);
  1287. }
  1288. }
  1289. if(strstr((char*)stop, ".") != NULL)
  1290. {
  1291. // Original data with mini second
  1292. if(strstr((char*)stop, "Z") != NULL)
  1293. {
  1294. // Original data with Z
  1295. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1296. &parseStop.year,
  1297. &parseStop.month,
  1298. &parseStop.mday,
  1299. &parseStop.hour,
  1300. &parseStop.min,
  1301. &parseStop.sec,
  1302. &parseStop.minSec);
  1303. }
  1304. else
  1305. {
  1306. // Original data without Z
  1307. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1308. &parseStop.year,
  1309. &parseStop.month,
  1310. &parseStop.mday,
  1311. &parseStop.hour,
  1312. &parseStop.min,
  1313. &parseStop.sec,
  1314. &parseStop.minSec,
  1315. &parseStop.tz_hour,
  1316. &parseStop.tz_min);
  1317. }
  1318. }
  1319. else
  1320. {
  1321. // Original data without mini second
  1322. if(strstr((char*)stop, "Z") != NULL)
  1323. {
  1324. // Original data with Z
  1325. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1326. &parseStop.year,
  1327. &parseStop.month,
  1328. &parseStop.mday,
  1329. &parseStop.hour,
  1330. &parseStop.min,
  1331. &parseStop.sec);
  1332. }
  1333. else
  1334. {
  1335. // Original data without Z
  1336. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1337. &parseStop.year,
  1338. &parseStop.month,
  1339. &parseStop.mday,
  1340. &parseStop.hour,
  1341. &parseStop.min,
  1342. &parseStop.sec,
  1343. &parseStop.tz_hour,
  1344. &parseStop.tz_min);
  1345. }
  1346. }
  1347. // Calculate date time difference
  1348. if((parseStart.scanedElement >=6) &&
  1349. (parseStop.scanedElement >=6))
  1350. {
  1351. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1352. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1353. tmStart.tm_year = parseStart.year - 1900;
  1354. tmStart.tm_mon = parseStart.month - 1;
  1355. tmStart.tm_mday = parseStart.mday;
  1356. tmStart.tm_hour = parseStart.hour;
  1357. tmStart.tm_min = parseStart.min;
  1358. tmStart.tm_sec = parseStart.sec;
  1359. tmStart.tm_gmtoff = 0;
  1360. tbStart.time = mktime(&tmStart);
  1361. tbStart.timezone = 0;
  1362. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1363. tmStop.tm_year = parseStop.year - 1900;
  1364. tmStop.tm_mon = parseStop.month - 1;
  1365. tmStop.tm_mday = parseStop.mday;
  1366. tmStop.tm_hour = parseStop.hour;
  1367. tmStop.tm_min = parseStop.min;
  1368. tmStop.tm_sec = parseStop.sec;
  1369. tmStop.tm_gmtoff = 0;
  1370. tbStop.time = mktime(&tmStop);
  1371. tbStop.timezone = 0;
  1372. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1373. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1374. //DEBUG_INFO("getStartStop(): %d\n", result);
  1375. }
  1376. else
  1377. {
  1378. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1379. }
  1380. return result;
  1381. }
  1382. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1383. {
  1384. FILE *fp;
  1385. char profileFileName[128];
  1386. char *line = NULL;
  1387. size_t len = 0;
  1388. time_t CurrentTime;
  1389. struct tm *tmComposite;
  1390. struct StructChargingProfile maxProfile;
  1391. struct StructChargingProfile compositeProfile;
  1392. uint8_t limitMax=0;
  1393. int compositePeriodIdx = 0;
  1394. //uint8_t isDurationNull = FALSE;
  1395. CurrentTime = time(NULL);
  1396. tmComposite=localtime(&CurrentTime);
  1397. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1398. if(isUnitA)
  1399. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1400. else
  1401. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1402. compositeProfile.ChargingSchedule.Duration = durationReq;
  1403. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1404. {
  1405. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1406. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1407. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1408. }
  1409. compositeProfile.ChargingProfileId = 0;
  1410. compositeProfile.StackLevel = 99 ;
  1411. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1412. maxProfile.ChargingProfileId = -1;
  1413. maxProfile.ChargingSchedule.Duration = -1;
  1414. system("rm -f /tmp/*.json");
  1415. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1416. // Search max profile
  1417. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1418. if((access(profileFileName, F_OK))!=-1)
  1419. {
  1420. fp = fopen(profileFileName, "r");
  1421. while(getline(&line, &len, fp) != -1)
  1422. {
  1423. json_object *obj = NULL;
  1424. obj = json_tokener_parse(line);
  1425. if(is_error(obj))
  1426. {
  1427. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1428. }
  1429. else
  1430. {
  1431. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1432. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1433. )
  1434. {
  1435. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1436. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1437. )
  1438. {
  1439. struct tm tmFrom, tmTo;
  1440. struct timeb tbFrom, tbTo;
  1441. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1442. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1443. {
  1444. tmFrom.tm_year -= 1900;
  1445. tmFrom.tm_mon -= 1;
  1446. tbFrom.time = mktime(&tmFrom);
  1447. tmTo.tm_year -= 1900;
  1448. tmTo.tm_mon -= 1;
  1449. tbTo.time = mktime(&tmTo);
  1450. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1451. {
  1452. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1453. {
  1454. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1455. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1456. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1457. }
  1458. if(maxProfile.ChargingProfileId == -1)
  1459. DEBUG_INFO("MaxProfile found.\n");
  1460. else
  1461. DEBUG_INFO("MaxProfile updated.\n");
  1462. // Required item
  1463. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1464. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1465. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1466. if(isUnitA)
  1467. {
  1468. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1469. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1470. {
  1471. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1472. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1473. 3:
  1474. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1475. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1476. }
  1477. }
  1478. else
  1479. {
  1480. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1481. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1482. {
  1483. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1484. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1485. 3:
  1486. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1487. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1488. }
  1489. }
  1490. // Optional item
  1491. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1492. {
  1493. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1494. }
  1495. else
  1496. {
  1497. sprintf((char*)maxProfile.ValidFrom, " ");
  1498. }
  1499. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1500. {
  1501. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1502. }
  1503. else
  1504. {
  1505. sprintf((char*)maxProfile.ValidTo, " ");
  1506. }
  1507. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1508. {
  1509. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1510. }
  1511. else
  1512. {
  1513. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1514. }
  1515. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1516. {
  1517. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1518. }
  1519. else
  1520. {
  1521. maxProfile.TransactionId = -1;
  1522. }
  1523. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1524. {
  1525. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1526. }
  1527. else
  1528. {
  1529. maxProfile.ChargingSchedule.Duration = 86400;
  1530. //isDurationNull = TRUE;
  1531. }
  1532. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1533. {
  1534. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1535. }
  1536. else
  1537. {
  1538. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1539. }
  1540. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1541. {
  1542. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1543. }
  1544. else
  1545. {
  1546. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1547. }
  1548. }
  1549. }
  1550. }
  1551. else
  1552. {
  1553. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1554. {
  1555. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1556. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1557. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1558. }
  1559. if(maxProfile.ChargingProfileId == -1)
  1560. DEBUG_INFO("MaxProfile found.\n");
  1561. else
  1562. DEBUG_INFO("MaxProfile updated.\n");
  1563. // Required item
  1564. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1565. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1566. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1567. if(isUnitA)
  1568. {
  1569. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1570. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1571. {
  1572. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1574. 3:
  1575. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1576. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1577. }
  1578. }
  1579. else
  1580. {
  1581. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1582. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1583. {
  1584. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1585. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1586. 3:
  1587. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1588. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1589. }
  1590. }
  1591. // Optional item
  1592. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1593. {
  1594. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1595. }
  1596. else
  1597. {
  1598. sprintf((char*)maxProfile.ValidFrom, " ");
  1599. }
  1600. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1601. {
  1602. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1603. }
  1604. else
  1605. {
  1606. sprintf((char*)maxProfile.ValidTo, " ");
  1607. }
  1608. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1609. {
  1610. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1611. }
  1612. else
  1613. {
  1614. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1615. }
  1616. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1617. {
  1618. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1619. }
  1620. else
  1621. {
  1622. maxProfile.TransactionId = -1;
  1623. }
  1624. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1625. {
  1626. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1627. }
  1628. else
  1629. {
  1630. maxProfile.ChargingSchedule.Duration = 86400;
  1631. //isDurationNull = TRUE;
  1632. }
  1633. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1634. {
  1635. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1636. }
  1637. else
  1638. {
  1639. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1640. }
  1641. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1642. {
  1643. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1644. }
  1645. else
  1646. {
  1647. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1648. }
  1649. }
  1650. }
  1651. }
  1652. json_object_put(obj);
  1653. }
  1654. fclose(fp);
  1655. /*
  1656. if(maxProfile.ChargingProfileId !=-1)
  1657. {
  1658. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1659. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1660. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1661. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1662. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1663. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1664. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1665. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1666. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1667. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1668. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1669. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1670. {
  1671. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1672. {
  1673. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1674. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1675. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1676. }
  1677. }
  1678. }
  1679. else
  1680. DEBUG_INFO("MaxProfile not found.\n");
  1681. DEBUG_INFO("------------------------------------\n");*/
  1682. }
  1683. if(maxProfile.ChargingProfileId != -1)
  1684. {
  1685. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1686. {
  1687. if(maxProfile.ChargingSchedule.Duration != -1)
  1688. {
  1689. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1690. 0:
  1691. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1692. }
  1693. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1694. {
  1695. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1696. {
  1697. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1698. 0:
  1699. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1700. if(idxPeriod > 0)
  1701. {
  1702. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1703. {
  1704. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1705. }
  1706. }
  1707. }
  1708. }
  1709. }
  1710. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1711. {
  1712. if(maxProfile.ChargingSchedule.Duration != -1)
  1713. {
  1714. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1715. }
  1716. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1717. {
  1718. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1719. {
  1720. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1721. if(idxPeriod > 0)
  1722. {
  1723. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1724. {
  1725. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1726. }
  1727. }
  1728. }
  1729. }
  1730. }
  1731. else
  1732. {
  1733. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1734. {
  1735. if(maxProfile.ChargingSchedule.Duration != -1)
  1736. {
  1737. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1738. 0:
  1739. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1740. }
  1741. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1742. {
  1743. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1744. {
  1745. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1746. 0:
  1747. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1748. if(idxPeriod > 0)
  1749. {
  1750. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1751. {
  1752. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1753. }
  1754. }
  1755. }
  1756. }
  1757. }
  1758. else
  1759. {
  1760. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  1761. {
  1762. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1763. 0:
  1764. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1765. }
  1766. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1767. {
  1768. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1769. {
  1770. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1771. 0:
  1772. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1773. if(idxPeriod > 0)
  1774. {
  1775. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1776. {
  1777. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1778. }
  1779. }
  1780. }
  1781. }
  1782. }
  1783. }
  1784. /*
  1785. DEBUG_INFO("MaxProfile after align.\n");
  1786. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1787. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1788. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1789. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1790. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1791. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1792. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1793. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1794. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1795. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1796. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1797. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1798. {
  1799. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1800. {
  1801. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1802. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1803. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1804. }
  1805. }
  1806. DEBUG_INFO("------------------------------------\n");*/
  1807. }
  1808. // Find each profile period quantity
  1809. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1810. {
  1811. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1812. limitMax = idx+1;
  1813. }
  1814. if(maxProfile.ChargingProfileId != -1)
  1815. {
  1816. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1817. {
  1818. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1819. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1820. (maxProfile.ChargingSchedule.Duration > 0))
  1821. {
  1822. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1823. {
  1824. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1825. compositePeriodIdx++;
  1826. }
  1827. else
  1828. {
  1829. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1830. }
  1831. }
  1832. }
  1833. }
  1834. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1835. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1836. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1837. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1838. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1839. {
  1840. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1841. {
  1842. compositeProfile.ChargingProfileId = 1;
  1843. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1844. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1845. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1846. }
  1847. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1848. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1849. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1850. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1851. }
  1852. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1853. if(line)
  1854. free(line);
  1855. }
  1856. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1857. {
  1858. FILE *fp;
  1859. char profileFileName[128];
  1860. char *line = NULL;
  1861. size_t len = 0;
  1862. time_t CurrentTime;
  1863. struct tm *tmComposite;
  1864. struct StructChargingProfile maxProfile;
  1865. struct StructChargingProfile defaultTxProfile;
  1866. struct StructChargingProfile txProfile;
  1867. struct StructChargingProfile compositeProfile;
  1868. struct StructChargingSchedulePeriod tmpPeriod;
  1869. uint8_t limitMax=0;
  1870. uint8_t limitDef=0;
  1871. uint8_t limitTx=0;
  1872. int compositePeriodIdx = 0;
  1873. CurrentTime = time(NULL);
  1874. tmComposite=localtime(&CurrentTime);
  1875. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1876. if(isUnitA)
  1877. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1878. else
  1879. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1880. compositeProfile.ChargingSchedule.Duration = durationReq;
  1881. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1882. {
  1883. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1884. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1885. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1886. }
  1887. compositeProfile.ChargingProfileId = 0;
  1888. compositeProfile.StackLevel = 99 ;
  1889. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1890. maxProfile.ChargingProfileId = -1;
  1891. defaultTxProfile.ChargingProfileId = -1;
  1892. txProfile.ChargingProfileId = -1;
  1893. maxProfile.ChargingSchedule.Duration = -1;
  1894. defaultTxProfile.ChargingSchedule.Duration = -1;
  1895. txProfile.ChargingSchedule.Duration = -1;
  1896. system("rm -f /tmp/*.json");
  1897. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1898. /*
  1899. * Search valid charging profile
  1900. */
  1901. //DEBUG_INFO("====================================\n");
  1902. // Search tx profile
  1903. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1904. if((access(profileFileName, F_OK))!=-1)
  1905. {
  1906. fp = fopen(profileFileName, "r");
  1907. while(getline(&line, &len, fp) != -1)
  1908. {
  1909. json_object *obj = NULL;
  1910. obj = json_tokener_parse(line);
  1911. if(is_error(obj))
  1912. {
  1913. DEBUG_ERROR("Parse txProfile from file error.\n");
  1914. }
  1915. else
  1916. {
  1917. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1918. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1919. )
  1920. {
  1921. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1922. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1923. )
  1924. {
  1925. struct tm tmFrom, tmTo;
  1926. struct timeb tbFrom, tbTo;
  1927. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1928. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1929. {
  1930. tmFrom.tm_year -= 1900;
  1931. tmFrom.tm_mon -= 1;
  1932. tbFrom.time = mktime(&tmFrom);
  1933. tmTo.tm_year -= 1900;
  1934. tmTo.tm_mon -= 1;
  1935. tbTo.time = mktime(&tmTo);
  1936. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1937. {
  1938. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1939. {
  1940. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1941. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1942. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1943. }
  1944. if(txProfile.ChargingProfileId == -1)
  1945. DEBUG_INFO("TxProfile found.\n");
  1946. else
  1947. DEBUG_INFO("TxProfile updated.\n");
  1948. // Required item
  1949. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1950. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1951. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1952. if(isUnitA)
  1953. {
  1954. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1955. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1956. {
  1957. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1958. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1959. 3:
  1960. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1961. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1962. }
  1963. }
  1964. else
  1965. {
  1966. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1967. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1968. {
  1969. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1970. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1971. 3:
  1972. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1973. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1974. }
  1975. }
  1976. // Optional item
  1977. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1978. {
  1979. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1980. }
  1981. else
  1982. {
  1983. sprintf((char*)txProfile.ValidFrom, " ");
  1984. }
  1985. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1986. {
  1987. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1988. }
  1989. else
  1990. {
  1991. sprintf((char*)txProfile.ValidTo, " ");
  1992. }
  1993. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1994. {
  1995. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1996. }
  1997. else
  1998. {
  1999. sprintf((char*)txProfile.RecurrencyKind, " ");
  2000. }
  2001. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2002. {
  2003. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2004. }
  2005. else
  2006. {
  2007. txProfile.TransactionId = -1;
  2008. }
  2009. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2010. {
  2011. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2012. }
  2013. else
  2014. {
  2015. txProfile.ChargingSchedule.Duration = 86400;
  2016. }
  2017. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2018. {
  2019. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2020. }
  2021. else
  2022. {
  2023. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2024. }
  2025. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2026. {
  2027. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2028. }
  2029. else
  2030. {
  2031. txProfile.ChargingSchedule.MinChargingRate = -1;
  2032. }
  2033. }
  2034. }
  2035. }
  2036. else
  2037. {
  2038. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2039. {
  2040. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2041. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2042. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2043. }
  2044. if(txProfile.ChargingProfileId == -1)
  2045. DEBUG_INFO("TxProfile found.\n");
  2046. else
  2047. DEBUG_INFO("TxProfile updated.\n");
  2048. // Required item
  2049. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2050. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2051. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2052. if(isUnitA)
  2053. {
  2054. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2055. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2056. {
  2057. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2058. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2059. 3:
  2060. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2061. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2062. }
  2063. }
  2064. else
  2065. {
  2066. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2067. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2068. {
  2069. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2070. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2071. 3:
  2072. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2073. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2074. }
  2075. }
  2076. // Optional item
  2077. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2078. {
  2079. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2080. }
  2081. else
  2082. {
  2083. sprintf((char*)txProfile.ValidFrom, " ");
  2084. }
  2085. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2086. {
  2087. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2088. }
  2089. else
  2090. {
  2091. sprintf((char*)txProfile.ValidTo, " ");
  2092. }
  2093. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2094. {
  2095. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2096. }
  2097. else
  2098. {
  2099. sprintf((char*)txProfile.RecurrencyKind, " ");
  2100. }
  2101. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2102. {
  2103. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2104. }
  2105. else
  2106. {
  2107. txProfile.TransactionId = -1;
  2108. }
  2109. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2110. {
  2111. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2112. }
  2113. else
  2114. {
  2115. txProfile.ChargingSchedule.Duration = 86400;
  2116. }
  2117. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2118. {
  2119. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2120. }
  2121. else
  2122. {
  2123. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2124. }
  2125. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2126. {
  2127. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2128. }
  2129. else
  2130. {
  2131. txProfile.ChargingSchedule.MinChargingRate = -1;
  2132. }
  2133. }
  2134. }
  2135. }
  2136. json_object_put(obj);
  2137. }
  2138. fclose(fp);
  2139. /*
  2140. if(txProfile.ChargingProfileId != -1)
  2141. {
  2142. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2143. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2144. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2145. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2146. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2147. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2148. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2149. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2150. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2151. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2152. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2153. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2154. {
  2155. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2156. {
  2157. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2158. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2159. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2160. }
  2161. }
  2162. }
  2163. else
  2164. DEBUG_INFO("TxProfile not found.\n");*/
  2165. }
  2166. // Search default tx profile
  2167. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2168. if((access(profileFileName, F_OK))==-1)
  2169. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2170. if((access(profileFileName, F_OK))!=-1)
  2171. {
  2172. fp = fopen(profileFileName, "r");
  2173. while(getline(&line, &len, fp) != -1)
  2174. {
  2175. json_object *obj = NULL;
  2176. obj = json_tokener_parse(line);
  2177. if(is_error(obj))
  2178. {
  2179. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2180. }
  2181. else
  2182. {
  2183. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2184. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2185. )
  2186. {
  2187. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2188. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2189. )
  2190. {
  2191. struct tm tmFrom, tmTo;
  2192. struct timeb tbFrom, tbTo;
  2193. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2194. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2195. {
  2196. tmFrom.tm_year -= 1900;
  2197. tmFrom.tm_mon -= 1;
  2198. tbFrom.time = mktime(&tmFrom);
  2199. tmTo.tm_year -= 1900;
  2200. tmTo.tm_mon -= 1;
  2201. tbTo.time = mktime(&tmTo);
  2202. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2203. {
  2204. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2205. {
  2206. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2207. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2208. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2209. }
  2210. if(defaultTxProfile.ChargingProfileId == -1)
  2211. DEBUG_INFO("TxDefaultProfile found.\n");
  2212. else
  2213. DEBUG_INFO("TxDefaultProfile updated.\n");
  2214. // Required item
  2215. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2216. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2217. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2218. if(isUnitA)
  2219. {
  2220. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2221. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2222. {
  2223. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2224. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2225. 3:
  2226. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2227. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2228. }
  2229. }
  2230. else
  2231. {
  2232. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2233. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2234. {
  2235. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2236. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2237. 3:
  2238. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2239. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2240. }
  2241. }
  2242. // Optional item
  2243. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2244. {
  2245. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2246. }
  2247. else
  2248. {
  2249. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2250. }
  2251. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2252. {
  2253. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2254. }
  2255. else
  2256. {
  2257. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2258. }
  2259. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2260. {
  2261. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2262. }
  2263. else
  2264. {
  2265. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2266. }
  2267. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2268. {
  2269. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2270. }
  2271. else
  2272. {
  2273. defaultTxProfile.TransactionId = -1;
  2274. }
  2275. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2276. {
  2277. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2278. }
  2279. else
  2280. {
  2281. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2282. }
  2283. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2284. {
  2285. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2286. }
  2287. else
  2288. {
  2289. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2290. }
  2291. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2292. {
  2293. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2294. }
  2295. else
  2296. {
  2297. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2298. }
  2299. }
  2300. }
  2301. }
  2302. else
  2303. {
  2304. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2305. {
  2306. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2307. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2308. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2309. }
  2310. if(defaultTxProfile.ChargingProfileId == -1)
  2311. DEBUG_INFO("TxDefaultProfile found.\n");
  2312. else
  2313. DEBUG_INFO("TxDefaultProfile updated.\n");
  2314. // Required item
  2315. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2316. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2317. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2318. if(isUnitA)
  2319. {
  2320. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2321. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2322. {
  2323. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2324. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2325. 3:
  2326. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2327. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2328. }
  2329. }
  2330. else
  2331. {
  2332. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2333. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2334. {
  2335. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2336. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2337. 3:
  2338. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2339. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2340. }
  2341. }
  2342. // Optional item
  2343. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2344. {
  2345. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2346. }
  2347. else
  2348. {
  2349. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2350. }
  2351. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2352. {
  2353. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2354. }
  2355. else
  2356. {
  2357. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2358. }
  2359. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2360. {
  2361. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2362. }
  2363. else
  2364. {
  2365. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2366. }
  2367. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2368. {
  2369. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2370. }
  2371. else
  2372. {
  2373. defaultTxProfile.TransactionId = -1;
  2374. }
  2375. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2376. {
  2377. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2378. }
  2379. else
  2380. {
  2381. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2382. }
  2383. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2384. {
  2385. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2386. }
  2387. else
  2388. {
  2389. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2390. }
  2391. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2392. {
  2393. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2394. }
  2395. else
  2396. {
  2397. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2398. }
  2399. }
  2400. }
  2401. }
  2402. json_object_put(obj);
  2403. }
  2404. fclose(fp);
  2405. /*
  2406. if(defaultTxProfile.ChargingProfileId != -1)
  2407. {
  2408. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2409. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2410. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2411. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2412. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2413. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2414. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2415. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2416. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2417. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2418. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2419. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2420. {
  2421. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2422. {
  2423. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2424. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2425. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2426. }
  2427. }
  2428. }
  2429. else
  2430. DEBUG_INFO("TxDefaultProfile not found.\n");
  2431. DEBUG_INFO("------------------------------------\n");*/
  2432. }
  2433. // Search max profile
  2434. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2435. if((access(profileFileName, F_OK))!=-1)
  2436. {
  2437. fp = fopen(profileFileName, "r");
  2438. while(getline(&line, &len, fp) != -1)
  2439. {
  2440. json_object *obj = NULL;
  2441. obj = json_tokener_parse(line);
  2442. if(is_error(obj))
  2443. {
  2444. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2445. }
  2446. else
  2447. {
  2448. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2449. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2450. )
  2451. {
  2452. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2453. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2454. )
  2455. {
  2456. struct tm tmFrom, tmTo;
  2457. struct timeb tbFrom, tbTo;
  2458. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2459. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2460. {
  2461. tmFrom.tm_year -= 1900;
  2462. tmFrom.tm_mon -= 1;
  2463. tbFrom.time = mktime(&tmFrom);
  2464. tmTo.tm_year -= 1900;
  2465. tmTo.tm_mon -= 1;
  2466. tbTo.time = mktime(&tmTo);
  2467. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2468. {
  2469. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2470. {
  2471. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2472. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2473. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2474. }
  2475. if(maxProfile.ChargingProfileId == -1)
  2476. DEBUG_INFO("MaxProfile found.\n");
  2477. else
  2478. DEBUG_INFO("MaxProfile updated.\n");
  2479. // Required item
  2480. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2481. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2482. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2483. if(isUnitA)
  2484. {
  2485. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2486. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2487. {
  2488. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2489. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2490. 3:
  2491. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2492. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2493. }
  2494. }
  2495. else
  2496. {
  2497. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2498. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2499. {
  2500. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2501. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2502. 3:
  2503. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2504. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2505. }
  2506. }
  2507. // Optional item
  2508. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2509. {
  2510. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2511. }
  2512. else
  2513. {
  2514. sprintf((char*)maxProfile.ValidFrom, " ");
  2515. }
  2516. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2517. {
  2518. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2519. }
  2520. else
  2521. {
  2522. sprintf((char*)maxProfile.ValidTo, " ");
  2523. }
  2524. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2525. {
  2526. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2527. }
  2528. else
  2529. {
  2530. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2531. }
  2532. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2533. {
  2534. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2535. }
  2536. else
  2537. {
  2538. maxProfile.TransactionId = -1;
  2539. }
  2540. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2541. {
  2542. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2543. }
  2544. else
  2545. {
  2546. maxProfile.ChargingSchedule.Duration = 86400;
  2547. }
  2548. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2549. {
  2550. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2551. }
  2552. else
  2553. {
  2554. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2555. }
  2556. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2557. {
  2558. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2559. }
  2560. else
  2561. {
  2562. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2563. }
  2564. }
  2565. }
  2566. }
  2567. else
  2568. {
  2569. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2570. {
  2571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2572. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2574. }
  2575. if(maxProfile.ChargingProfileId == -1)
  2576. DEBUG_INFO("MaxProfile found.\n");
  2577. else
  2578. DEBUG_INFO("MaxProfile updated.\n");
  2579. // Required item
  2580. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2581. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2582. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2583. if(isUnitA)
  2584. {
  2585. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2586. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2587. {
  2588. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2589. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2590. 3:
  2591. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2592. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2593. }
  2594. }
  2595. else
  2596. {
  2597. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2598. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2599. {
  2600. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2601. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2602. 3:
  2603. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2604. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2605. }
  2606. }
  2607. // Optional item
  2608. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2609. {
  2610. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2611. }
  2612. else
  2613. {
  2614. sprintf((char*)maxProfile.ValidFrom, " ");
  2615. }
  2616. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2617. {
  2618. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2619. }
  2620. else
  2621. {
  2622. sprintf((char*)maxProfile.ValidTo, " ");
  2623. }
  2624. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2625. {
  2626. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2627. }
  2628. else
  2629. {
  2630. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2631. }
  2632. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2633. {
  2634. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2635. }
  2636. else
  2637. {
  2638. maxProfile.TransactionId = -1;
  2639. }
  2640. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2641. {
  2642. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2643. }
  2644. else
  2645. {
  2646. maxProfile.ChargingSchedule.Duration = 86400;
  2647. }
  2648. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2649. {
  2650. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2651. }
  2652. else
  2653. {
  2654. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2655. }
  2656. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2657. {
  2658. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2659. }
  2660. else
  2661. {
  2662. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2663. }
  2664. }
  2665. }
  2666. }
  2667. json_object_put(obj);
  2668. }
  2669. fclose(fp);
  2670. /*
  2671. if(maxProfile.ChargingProfileId !=-1)
  2672. {
  2673. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2674. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2675. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2676. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2677. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2678. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2679. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2680. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2681. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2682. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2683. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2684. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2685. {
  2686. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2687. {
  2688. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2689. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2690. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2691. }
  2692. }
  2693. }
  2694. else
  2695. DEBUG_INFO("MaxProfile not found.\n");
  2696. DEBUG_INFO("------------------------------------\n");*/
  2697. }
  2698. /*
  2699. * Align found profile start schedule & periods
  2700. */
  2701. //DEBUG_INFO("====================================\n");
  2702. /*
  2703. // For local test usage, force modify found profile start schedule info
  2704. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  2705. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  2706. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  2707. */
  2708. if(txProfile.ChargingProfileId != -1)
  2709. {
  2710. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2711. {
  2712. if(txProfile.ChargingSchedule.Duration != -1)
  2713. {
  2714. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2715. 0:
  2716. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2717. }
  2718. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2719. {
  2720. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2721. {
  2722. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2723. 0:
  2724. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2725. if(idxPeriod > 0)
  2726. {
  2727. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2728. {
  2729. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2730. }
  2731. }
  2732. }
  2733. }
  2734. }
  2735. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2736. {
  2737. if(txProfile.ChargingSchedule.Duration != -1)
  2738. {
  2739. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2740. 0:
  2741. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2742. }
  2743. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2744. {
  2745. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2746. {
  2747. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2748. 0:
  2749. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2750. if(idxPeriod > 0)
  2751. {
  2752. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2753. {
  2754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2755. }
  2756. }
  2757. }
  2758. }
  2759. }
  2760. else
  2761. {
  2762. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2763. {
  2764. if(txProfile.ChargingSchedule.Duration != -1)
  2765. {
  2766. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2767. 0:
  2768. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2769. }
  2770. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2771. {
  2772. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2773. {
  2774. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2775. 0:
  2776. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2777. if(idxPeriod > 0)
  2778. {
  2779. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2780. {
  2781. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2782. }
  2783. }
  2784. }
  2785. }
  2786. }
  2787. else
  2788. {
  2789. if(txProfile.ChargingSchedule.Duration != -1)
  2790. {
  2791. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2792. 0:
  2793. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2794. }
  2795. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2796. {
  2797. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2798. {
  2799. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2800. 0:
  2801. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2802. if(idxPeriod > 0)
  2803. {
  2804. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2805. {
  2806. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2807. }
  2808. }
  2809. }
  2810. }
  2811. }
  2812. }
  2813. /*
  2814. DEBUG_INFO("txProfile after align.\n");
  2815. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2816. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2817. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2818. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2819. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2820. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2821. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2822. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2823. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2824. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2825. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2826. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2827. {
  2828. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2829. {
  2830. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2831. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2832. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2833. }
  2834. }*/
  2835. }
  2836. if(defaultTxProfile.ChargingProfileId != -1)
  2837. {
  2838. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2839. {
  2840. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2841. {
  2842. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2843. 0:
  2844. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2845. }
  2846. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2847. {
  2848. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2849. {
  2850. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2851. 0:
  2852. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2853. if(idxPeriod > 0)
  2854. {
  2855. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2856. {
  2857. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2858. }
  2859. }
  2860. }
  2861. }
  2862. }
  2863. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2864. {
  2865. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2866. {
  2867. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2868. 0:
  2869. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2870. }
  2871. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2872. {
  2873. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2874. {
  2875. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2876. 0:
  2877. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2878. if(idxPeriod > 0)
  2879. {
  2880. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2881. {
  2882. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2883. }
  2884. }
  2885. }
  2886. }
  2887. }
  2888. else
  2889. {
  2890. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2891. {
  2892. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2893. {
  2894. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2895. 0:
  2896. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2897. }
  2898. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2899. {
  2900. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2901. {
  2902. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2903. 0:
  2904. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2905. if(idxPeriod > 0)
  2906. {
  2907. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2908. {
  2909. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2910. }
  2911. }
  2912. }
  2913. }
  2914. }
  2915. else
  2916. {
  2917. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2918. {
  2919. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2920. 0:
  2921. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2922. }
  2923. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2924. {
  2925. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2926. {
  2927. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2928. 0:
  2929. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2930. if(idxPeriod > 0)
  2931. {
  2932. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2933. {
  2934. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2935. }
  2936. }
  2937. }
  2938. }
  2939. }
  2940. }
  2941. /*
  2942. DEBUG_INFO("defaultTxProfile after align.\n");
  2943. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2944. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2945. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2946. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2947. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2948. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2949. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2950. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2951. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2952. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2953. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2954. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2955. {
  2956. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2957. {
  2958. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2959. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2960. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2961. }
  2962. }
  2963. DEBUG_INFO("------------------------------------\n");*/
  2964. }
  2965. if(maxProfile.ChargingProfileId != -1)
  2966. {
  2967. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2968. {
  2969. if(maxProfile.ChargingSchedule.Duration != -1)
  2970. {
  2971. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2972. 0:
  2973. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2974. }
  2975. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2976. {
  2977. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2978. {
  2979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2980. 0:
  2981. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2982. if(idxPeriod > 0)
  2983. {
  2984. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2985. {
  2986. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2987. }
  2988. }
  2989. }
  2990. }
  2991. }
  2992. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2993. {
  2994. if(maxProfile.ChargingSchedule.Duration != -1)
  2995. {
  2996. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2997. 0:
  2998. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2999. }
  3000. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3001. {
  3002. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3003. {
  3004. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3005. 0:
  3006. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3007. if(idxPeriod > 0)
  3008. {
  3009. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3010. {
  3011. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3012. }
  3013. }
  3014. }
  3015. }
  3016. }
  3017. else
  3018. {
  3019. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3020. {
  3021. if(maxProfile.ChargingSchedule.Duration != -1)
  3022. {
  3023. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3024. 0:
  3025. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3026. }
  3027. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3028. {
  3029. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3030. {
  3031. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3032. 0:
  3033. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3034. if(idxPeriod > 0)
  3035. {
  3036. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3037. {
  3038. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3039. }
  3040. }
  3041. }
  3042. }
  3043. }
  3044. else
  3045. {
  3046. if(maxProfile.ChargingSchedule.Duration != -1)
  3047. {
  3048. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3049. 0:
  3050. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3051. }
  3052. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3053. {
  3054. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3055. {
  3056. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3057. 0:
  3058. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3059. if(idxPeriod > 0)
  3060. {
  3061. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3062. {
  3063. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3064. }
  3065. }
  3066. }
  3067. }
  3068. }
  3069. }
  3070. /*
  3071. DEBUG_INFO("MaxProfile after align.\n");
  3072. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3073. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3074. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3075. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3076. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3077. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3078. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3079. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3080. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3081. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3082. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3083. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3084. {
  3085. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3086. {
  3087. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3088. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3089. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3090. }
  3091. }
  3092. DEBUG_INFO("------------------------------------\n");*/
  3093. }
  3094. /*
  3095. * Merge to conposite schedule
  3096. */
  3097. //DEBUG_INFO("====================================\n");
  3098. // Find each profile period quantity
  3099. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3100. {
  3101. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3102. limitMax = idx+1;
  3103. }
  3104. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3105. {
  3106. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3107. limitDef = idx+1;
  3108. }
  3109. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3110. {
  3111. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3112. limitTx = idx+1;
  3113. }
  3114. // TxProfile found, composite schedule based on it
  3115. if(txProfile.ChargingProfileId != -1)
  3116. {
  3117. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3118. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3119. {
  3120. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3121. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3122. (txProfile.ChargingSchedule.Duration > 0))
  3123. {
  3124. if(maxProfile.ChargingProfileId != -1)
  3125. {
  3126. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3127. {
  3128. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3129. {
  3130. if((maxProfile.ChargingSchedule.Duration > 0))
  3131. {
  3132. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3133. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3134. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3135. }
  3136. else
  3137. {
  3138. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3139. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3140. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3141. }
  3142. }
  3143. if(idxMaxPeriod == (limitMax-1))
  3144. {
  3145. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3146. {
  3147. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3148. {
  3149. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3150. compositePeriodIdx++;
  3151. }
  3152. else
  3153. {
  3154. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3155. }
  3156. }
  3157. }
  3158. }
  3159. }
  3160. else
  3161. {
  3162. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3163. {
  3164. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3165. compositePeriodIdx++;
  3166. }
  3167. else
  3168. {
  3169. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3170. }
  3171. }
  3172. }
  3173. if(idxTxPeriod == (limitTx-1))
  3174. {
  3175. if(defaultTxProfile.ChargingProfileId != -1)
  3176. {
  3177. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3178. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3179. {
  3180. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3181. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3182. (defaultTxProfile.ChargingSchedule.Duration>0))
  3183. {
  3184. if(maxProfile.ChargingProfileId != -1)
  3185. {
  3186. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3187. {
  3188. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3189. {
  3190. if((maxProfile.ChargingSchedule.Duration > 0))
  3191. {
  3192. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3193. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3194. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3195. }
  3196. else
  3197. {
  3198. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3199. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3200. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3201. }
  3202. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3203. {
  3204. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3205. {
  3206. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3207. compositePeriodIdx++;
  3208. }
  3209. else
  3210. {
  3211. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3212. }
  3213. }
  3214. // Delete duplicate period
  3215. if(compositePeriodIdx > 1)
  3216. {
  3217. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3218. {
  3219. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3220. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3221. compositePeriodIdx -= 1;
  3222. }
  3223. }
  3224. }
  3225. else
  3226. {
  3227. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3228. {
  3229. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3230. compositePeriodIdx++;
  3231. }
  3232. else
  3233. {
  3234. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3235. }
  3236. break;
  3237. }
  3238. }
  3239. }
  3240. else
  3241. {
  3242. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3243. {
  3244. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3245. compositePeriodIdx++;
  3246. }
  3247. else
  3248. {
  3249. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3250. }
  3251. }
  3252. }
  3253. }
  3254. }
  3255. }
  3256. }
  3257. }
  3258. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3259. else if(defaultTxProfile.ChargingProfileId != -1)
  3260. {
  3261. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3262. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3263. {
  3264. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3265. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3266. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3267. {
  3268. if(maxProfile.ChargingProfileId != -1)
  3269. {
  3270. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3271. {
  3272. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3273. {
  3274. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3275. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3276. if((maxProfile.ChargingSchedule.Duration > 0))
  3277. {
  3278. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3279. }
  3280. else
  3281. {
  3282. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3283. }
  3284. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3285. {
  3286. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3287. {
  3288. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3289. compositePeriodIdx++;
  3290. }
  3291. else
  3292. {
  3293. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3294. }
  3295. }
  3296. // Delete duplicate period
  3297. if(compositePeriodIdx > 1)
  3298. {
  3299. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3300. {
  3301. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3302. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3303. compositePeriodIdx -= 1;
  3304. }
  3305. }
  3306. }
  3307. else
  3308. {
  3309. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3310. {
  3311. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3312. compositePeriodIdx++;
  3313. }
  3314. else
  3315. {
  3316. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3317. }
  3318. break;
  3319. }
  3320. }
  3321. }
  3322. else
  3323. {
  3324. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3325. {
  3326. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3327. compositePeriodIdx++;
  3328. }
  3329. else
  3330. {
  3331. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3332. }
  3333. }
  3334. }
  3335. }
  3336. }
  3337. // Fill other period by MaxProfile
  3338. if(maxProfile.ChargingProfileId != -1)
  3339. {
  3340. if(compositePeriodIdx==0)
  3341. {
  3342. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3343. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3344. {
  3345. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3346. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3347. (maxProfile.ChargingSchedule.Duration > 0))
  3348. {
  3349. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3350. {
  3351. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3352. compositePeriodIdx++;
  3353. }
  3354. else
  3355. {
  3356. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3357. }
  3358. }
  3359. }
  3360. }
  3361. else
  3362. {
  3363. int lastCompositePeriodIdx = compositePeriodIdx;
  3364. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3365. {
  3366. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3367. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3368. (maxProfile.ChargingSchedule.Duration > 0))
  3369. {
  3370. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3371. {
  3372. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3373. {
  3374. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3375. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3376. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3377. }
  3378. else
  3379. {
  3380. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3381. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3382. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3383. }
  3384. }
  3385. if(tmpPeriod.Limit != -1)
  3386. {
  3387. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3388. {
  3389. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3390. {
  3391. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3392. compositePeriodIdx++;
  3393. }
  3394. else
  3395. {
  3396. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3397. }
  3398. }
  3399. // Delete duplicate period
  3400. if(compositePeriodIdx > 1)
  3401. {
  3402. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3403. {
  3404. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3405. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3406. compositePeriodIdx -= 1;
  3407. }
  3408. }
  3409. }
  3410. }
  3411. }
  3412. }
  3413. }
  3414. compositeProfile.ChargingSchedule.Duration = durationReq;
  3415. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3416. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3417. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3418. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3419. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3420. {
  3421. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3422. {
  3423. compositeProfile.ChargingProfileId = 1;
  3424. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3425. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3426. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3427. }
  3428. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3429. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3430. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3431. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3432. }
  3433. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3434. if(line)
  3435. free(line);
  3436. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3437. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3438. }
  3439. //==========================================
  3440. // Init all share memory
  3441. //==========================================
  3442. int InitShareMemory()
  3443. {
  3444. int result = PASS;
  3445. int MeterSMId;
  3446. //creat ShmSysConfigAndInfo
  3447. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3448. {
  3449. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3450. result = FAIL;
  3451. }
  3452. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3453. {
  3454. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3455. result = FAIL;
  3456. }
  3457. else
  3458. {}
  3459. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3460. {
  3461. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3462. result = FAIL;
  3463. }
  3464. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3465. {
  3466. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3467. result = FAIL;
  3468. }
  3469. else
  3470. {}
  3471. //creat ShmPsuData
  3472. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3473. {
  3474. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3475. result = FAIL;
  3476. }
  3477. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3478. {
  3479. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3480. result = FAIL;
  3481. }
  3482. else
  3483. {}
  3484. //link ShmOCPP16Data
  3485. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3486. {
  3487. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3488. result = FAIL;
  3489. }
  3490. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3491. {
  3492. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3493. result = FAIL;
  3494. }
  3495. else
  3496. {}
  3497. //creat ShmOCPP16DataPH
  3498. if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3499. {
  3500. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3501. result = FAIL;
  3502. }
  3503. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3504. {
  3505. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3506. result = FAIL;
  3507. }
  3508. else
  3509. {}
  3510. /****************************** For Initial Settings************************************************/
  3511. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3512. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3513. // allocate Configuration memory address
  3514. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3515. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3516. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3517. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3518. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3519. //offline MeterValue Interval
  3520. TempMeterValueInterval = 0;
  3521. return result;
  3522. }
  3523. int ProcessShareMemory()
  3524. {
  3525. int result = PASS;
  3526. if(InitShareMemory() == FAIL)
  3527. {
  3528. DEBUG_ERROR("InitShareMemory NG\n");
  3529. if(ShmStatusCodeData!=NULL)
  3530. {
  3531. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3532. }
  3533. result = FAIL;
  3534. }
  3535. // Model name parsing
  3536. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3537. {
  3538. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3539. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3540. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3541. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3542. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3543. ) // 'D' means DC
  3544. {
  3545. // DO series
  3546. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3547. {
  3548. gunTotalNumber += 1;
  3549. gunType[gun_index] = GUN_TYPE_DO;
  3550. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3551. {
  3552. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3553. {
  3554. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3555. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3556. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3557. }
  3558. }
  3559. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3560. {
  3561. case Gun_Type_Chademo:
  3562. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3563. break;
  3564. case Gun_Type_CCS_2:
  3565. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3566. break;
  3567. case Gun_Type_GB:
  3568. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3569. break;
  3570. case Gun_Type_AC:
  3571. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3572. break;
  3573. default:
  3574. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3575. break;
  3576. }
  3577. }
  3578. }
  3579. else
  3580. {
  3581. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3582. {
  3583. gunTotalNumber += 1;
  3584. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3585. {
  3586. case Gun_Type_Chademo:
  3587. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3588. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3589. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  3590. {
  3591. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  3592. {
  3593. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3594. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3595. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  3596. }
  3597. }
  3598. break;
  3599. case Gun_Type_CCS_2:
  3600. gunType[gun_index] = GUN_TYPE_CCS;
  3601. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3602. for (int index = 0; index < CCS_QUANTITY; index++)
  3603. {
  3604. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  3605. {
  3606. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3607. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3608. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  3609. }
  3610. }
  3611. break;
  3612. case Gun_Type_GB:
  3613. gunType[gun_index] = GUN_TYPE_GBT;
  3614. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3615. for (int index = 0; index < GB_QUANTITY; index++)
  3616. {
  3617. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  3618. {
  3619. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3620. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3621. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  3622. }
  3623. }
  3624. break;
  3625. case Gun_Type_AC:
  3626. gunType[gun_index] = GUN_TYPE_AC;
  3627. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3628. for (int index = 0; index < AC_QUANTITY; index++)
  3629. {
  3630. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  3631. {
  3632. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3633. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3634. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  3635. }
  3636. }
  3637. break;
  3638. default:
  3639. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3640. break;
  3641. }
  3642. }
  3643. }
  3644. }
  3645. else
  3646. {
  3647. DEBUG_ERROR("Model name parsing fail.\n");
  3648. result = FAIL;
  3649. }
  3650. if(result != PASS)sleep(5);
  3651. return result;
  3652. }
  3653. void checkRemoteStart(uint8_t connectorIdInt)
  3654. {
  3655. uint8_t tempIndex;
  3656. int result = PASS;
  3657. char cmdBuf[512];
  3658. //check Transaction active
  3659. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3660. {
  3661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3662. {
  3663. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3664. }
  3665. else
  3666. {
  3667. tempIndex = connectorIdInt -1;
  3668. }
  3669. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3670. {
  3671. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3672. {
  3673. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3674. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3675. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3676. {
  3677. //Reserved
  3678. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3679. }
  3680. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3681. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3682. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3683. {
  3684. //Reserved
  3685. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3686. result = FAIL;
  3687. goto end;
  3688. }
  3689. else
  3690. {
  3691. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3692. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3693. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3694. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3695. {
  3696. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3697. result = FAIL;
  3698. goto end;
  3699. }
  3700. }//END FOR ELSE
  3701. }
  3702. }// END FOR CHAdeMO_QUANTITY
  3703. }
  3704. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3705. {
  3706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3707. {
  3708. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3709. }
  3710. else
  3711. {
  3712. tempIndex = connectorIdInt -1;
  3713. }
  3714. for (int index = 0; index < CCS_QUANTITY; index++)
  3715. {
  3716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3717. {
  3718. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3719. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3720. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3721. {
  3722. //Reserved
  3723. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3724. }
  3725. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3726. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3727. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3728. {
  3729. //Reserved
  3730. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3731. result = FAIL;
  3732. goto end;
  3733. }
  3734. else
  3735. {
  3736. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3737. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3738. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3739. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3740. {
  3741. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3742. result = FAIL;
  3743. goto end;
  3744. }
  3745. }// END FOR ELSE
  3746. }
  3747. }// END FOR CCS_QUANTITY
  3748. }
  3749. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3750. {
  3751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3752. {
  3753. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3754. }
  3755. else
  3756. {
  3757. tempIndex = connectorIdInt -1;
  3758. }
  3759. for (int index = 0; index < GB_QUANTITY; index++)
  3760. {
  3761. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3762. {
  3763. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3764. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3765. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3766. {
  3767. //Reserved
  3768. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3769. }
  3770. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3771. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3772. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3773. {
  3774. //Reserved
  3775. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3776. result = FAIL;
  3777. goto end;
  3778. }
  3779. else
  3780. {
  3781. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3782. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3783. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3784. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3785. {
  3786. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3787. result = FAIL;
  3788. goto end;
  3789. }
  3790. }// END FOR ELSE
  3791. }
  3792. } // END FOR GB_QUANTITY
  3793. }
  3794. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3795. {
  3796. tempIndex = connectorIdInt -1;
  3797. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3798. {
  3799. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3800. {
  3801. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3802. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3803. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3804. {
  3805. //Reserved
  3806. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3807. }
  3808. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3809. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3810. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3811. {
  3812. //Reserved
  3813. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3814. result = FAIL;
  3815. goto end;
  3816. }
  3817. else
  3818. {
  3819. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3820. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3821. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3822. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3823. {
  3824. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3825. result = FAIL;
  3826. goto end;
  3827. }
  3828. }// END FOR ELSE
  3829. }
  3830. } // END FOR GB_QUANTITY
  3831. }
  3832. else
  3833. {
  3834. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3835. {
  3836. tempIndex = 2;
  3837. }
  3838. else
  3839. {
  3840. tempIndex = connectorIdInt -1;
  3841. }
  3842. for (int index = 0; index < AC_QUANTITY; index++)
  3843. {
  3844. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3845. {
  3846. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3847. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3848. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3849. {
  3850. //Reserved
  3851. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3852. }
  3853. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3854. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3855. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3856. {
  3857. //Reserved
  3858. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3859. result = FAIL;
  3860. goto end;
  3861. }
  3862. else
  3863. {
  3864. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3865. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3866. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3867. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3868. {
  3869. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3870. result = FAIL;
  3871. goto end;
  3872. }
  3873. }//END FOR ELSE
  3874. }
  3875. }// END FOR AC_QUANTITY
  3876. }
  3877. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3878. {
  3879. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3880. {
  3881. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3882. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3883. {
  3884. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3885. system(cmdBuf);
  3886. }
  3887. }
  3888. else
  3889. {
  3890. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3891. result = FAIL;
  3892. }
  3893. }
  3894. end:
  3895. if(result == PASS)
  3896. {
  3897. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3898. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3899. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3900. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3901. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3902. }
  3903. }
  3904. void CheckSystemValue(void)
  3905. {
  3906. char filenmae[100]={0};
  3907. char str[100]={0};
  3908. int tempIndex = 0;
  3909. //===============================
  3910. // send Heartbeat
  3911. //===============================
  3912. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3913. {
  3914. //parameter for test
  3915. sendHeartbeatRequest(0);
  3916. //==============================================
  3917. // Reset Waiting Time
  3918. //==============================================
  3919. HeartBeatWithNOResponse += 2;
  3920. }
  3921. //===============================
  3922. // Credit deduct report
  3923. //===============================
  3924. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3925. {
  3926. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3927. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3928. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3929. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3930. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3931. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3932. }
  3933. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3934. {
  3935. OCPP_query_deduct_info();
  3936. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3937. }
  3938. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3939. {
  3940. // ClockAlign MeterValue
  3941. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3942. {
  3943. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3944. {
  3945. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3946. {
  3947. tempIndex = ((gun_index==2) ? 1: 0);
  3948. }
  3949. else
  3950. {
  3951. tempIndex = gun_index;
  3952. }
  3953. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3954. {
  3955. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3956. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3957. {
  3958. reqClockAlignMeter[gun_index] = 1;
  3959. }
  3960. }// End for CHAdeMO
  3961. }
  3962. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3963. {
  3964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3965. {
  3966. tempIndex = ((gun_index==2) ? 1: 0);
  3967. }
  3968. else
  3969. {
  3970. tempIndex = gun_index;
  3971. }
  3972. for (int index = 0; index < CCS_QUANTITY; index++)
  3973. {
  3974. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3975. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3976. {
  3977. reqClockAlignMeter[gun_index] = 1;
  3978. }
  3979. } // End for CCS
  3980. }
  3981. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3982. {
  3983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3984. {
  3985. tempIndex = ((gun_index==2) ? 1: 0);
  3986. }
  3987. else
  3988. {
  3989. tempIndex = gun_index;
  3990. }
  3991. for (int index = 0; index < GB_QUANTITY; index++)
  3992. {
  3993. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3994. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3995. {
  3996. reqClockAlignMeter[gun_index] = 1;
  3997. }
  3998. }// End for GB
  3999. }
  4000. else if(gunType[gun_index] == GUN_TYPE_DO)
  4001. {
  4002. tempIndex = gun_index;
  4003. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4004. {
  4005. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4006. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4007. {
  4008. reqClockAlignMeter[gun_index] = 1;
  4009. }
  4010. }
  4011. }
  4012. else
  4013. {
  4014. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4015. {
  4016. tempIndex = 2;
  4017. }
  4018. else
  4019. {
  4020. tempIndex = gun_index;
  4021. }
  4022. for (int index = 0; index < AC_QUANTITY; index++)
  4023. {
  4024. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4025. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4026. {
  4027. reqClockAlignMeter[gun_index] = 1;
  4028. }
  4029. }//End for AC
  4030. }
  4031. }
  4032. }
  4033. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4034. {
  4035. //==========================================
  4036. // Check remote start without connector id
  4037. //==========================================
  4038. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  4039. {
  4040. int connectorIdInt = -1;
  4041. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4042. {
  4043. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4044. {
  4045. connectorIdInt = (gun_index+1);
  4046. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4047. checkRemoteStart(connectorIdInt);
  4048. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4049. break;
  4050. }
  4051. }
  4052. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4053. {
  4054. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4055. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4056. }
  4057. }
  4058. //==========================================
  4059. // csu trigger DataTransferReq
  4060. //==========================================
  4061. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4062. {
  4063. sendDataTransferRequest(gun_index);
  4064. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4065. }
  4066. //===============================
  4067. // CSU Trigger Authorize Request
  4068. //===============================
  4069. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4070. {
  4071. sendAuthorizeRequest(0);
  4072. authorizeRetryTimes = authorizeRetryTimes + 1;
  4073. if(authorizeRetryTimes < 3)
  4074. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4075. }
  4076. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4077. {
  4078. authorizeRetryTimes = 0;
  4079. SetOcppConnStatus(FALSE);
  4080. server_sign = FALSE;
  4081. }
  4082. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0)&& (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1))
  4083. {
  4084. sendAuthorizeRequest(0);
  4085. }
  4086. //==============================================
  4087. // Charger start transaction
  4088. //==============================================
  4089. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4090. {
  4091. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4092. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4093. sendStartTransactionRequest(gun_index);
  4094. refreshStartTimer(&clientTime.StartTransaction);
  4095. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4096. //storeTempStopTransaction(gun_index);
  4097. }
  4098. //==============================================
  4099. // Charger stop transaction
  4100. //==============================================
  4101. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4102. {
  4103. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4104. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4105. sendStopTransactionRequest(gun_index);
  4106. refreshStartTimer(&clientTime.StopTransaction);
  4107. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4108. }
  4109. //==============================================
  4110. // Charger status report
  4111. //==============================================
  4112. //--- Check Mode Change ---//
  4113. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4114. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4115. {
  4116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4117. {
  4118. tempIndex = ((gun_index==2) ? 1: 0);
  4119. }
  4120. else
  4121. {
  4122. tempIndex = gun_index;
  4123. }
  4124. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4125. {
  4126. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4127. {
  4128. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4129. {
  4130. // Sent unplug message for California pricing logic
  4131. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4132. {
  4133. uint8_t ts[36];
  4134. getNowDatetime(ts);
  4135. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4136. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4137. if(strcmp((char*)dmsVersion, "2.0")==0)
  4138. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4139. else
  4140. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4141. sendUnplugByDataTransferRequest(gun_index);
  4142. interLock.isSentUnplug[gun_index] = 1;
  4143. }
  4144. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4145. {
  4146. interLock.isSentUnplug[gun_index] = 0;
  4147. }
  4148. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4149. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4150. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4151. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4152. {
  4153. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4154. if((access(filenmae,F_OK))!=-1)
  4155. {
  4156. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4157. sprintf(str,"rm -f %s",filenmae);
  4158. system(str);
  4159. }
  4160. }
  4161. }
  4162. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4163. #if 1 // for TempStopTransaction
  4164. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4165. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4166. {
  4167. checkTempStopTransaction(gun_index);
  4168. }
  4169. #endif
  4170. }
  4171. }
  4172. }
  4173. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4174. {
  4175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4176. {
  4177. tempIndex = ((gun_index==2) ? 1: 0);
  4178. }
  4179. else
  4180. {
  4181. tempIndex = gun_index;
  4182. }
  4183. for (int index = 0; index < CCS_QUANTITY; index++)
  4184. {
  4185. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4186. {
  4187. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  4188. {
  4189. // Sent unplug message for California pricing logic
  4190. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4191. {
  4192. uint8_t ts[36];
  4193. getNowDatetime(ts);
  4194. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4195. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4196. if(strcmp((char*)dmsVersion, "2.0")==0)
  4197. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4198. else
  4199. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4200. sendUnplugByDataTransferRequest(gun_index);
  4201. interLock.isSentUnplug[gun_index] = 1;
  4202. }
  4203. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4204. {
  4205. interLock.isSentUnplug[gun_index] = 0;
  4206. }
  4207. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4208. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4209. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4210. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4211. {
  4212. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4213. if((access(filenmae,F_OK))!=-1)
  4214. {
  4215. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4216. sprintf(str,"rm -f %s",filenmae);
  4217. system(str);
  4218. }
  4219. }
  4220. }
  4221. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4222. #if 1 // for TempStopTransaction
  4223. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4224. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4225. {
  4226. checkTempStopTransaction(gun_index);
  4227. }
  4228. #endif
  4229. }
  4230. }
  4231. }
  4232. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4233. {
  4234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4235. {
  4236. tempIndex = ((gun_index==2) ? 1: 0);
  4237. }
  4238. else
  4239. {
  4240. tempIndex = gun_index;
  4241. }
  4242. for (int index = 0; index < GB_QUANTITY; index++)
  4243. {
  4244. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4245. {
  4246. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4247. {
  4248. // Sent unplug message for California pricing logic
  4249. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4250. {
  4251. uint8_t ts[36];
  4252. getNowDatetime(ts);
  4253. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4254. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4255. if(strcmp((char*)dmsVersion, "2.0")==0)
  4256. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4257. else
  4258. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4259. sendUnplugByDataTransferRequest(gun_index);
  4260. interLock.isSentUnplug[gun_index] = 1;
  4261. }
  4262. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4263. {
  4264. interLock.isSentUnplug[gun_index] = 0;
  4265. }
  4266. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4267. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4268. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4269. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4270. {
  4271. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4272. if((access(filenmae,F_OK))!=-1)
  4273. {
  4274. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4275. sprintf(str,"rm -f %s",filenmae);
  4276. system(str);
  4277. }
  4278. }
  4279. }
  4280. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4281. #if 1 // for TempStopTransaction
  4282. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4283. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4284. {
  4285. checkTempStopTransaction(gun_index);
  4286. }
  4287. #endif
  4288. }
  4289. }
  4290. }
  4291. else if(gunType[gun_index] == GUN_TYPE_DO)
  4292. {
  4293. tempIndex = gun_index;
  4294. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4295. {
  4296. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4297. {
  4298. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4299. {
  4300. // Sent unplug message for California pricing logic
  4301. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4302. {
  4303. uint8_t ts[36];
  4304. getNowDatetime(ts);
  4305. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4306. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4307. if(strcmp((char*)dmsVersion, "2.0")==0)
  4308. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4309. else
  4310. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4311. sendUnplugByDataTransferRequest(gun_index);
  4312. interLock.isSentUnplug[gun_index] = 1;
  4313. }
  4314. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4315. {
  4316. interLock.isSentUnplug[gun_index] = 0;
  4317. }
  4318. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4319. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4320. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4321. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  4322. {
  4323. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4324. if((access(filenmae,F_OK))!=-1)
  4325. {
  4326. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4327. sprintf(str,"rm -f %s",filenmae);
  4328. system(str);
  4329. }
  4330. }
  4331. }
  4332. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4333. #if 1 // for TempStopTransaction
  4334. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4335. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4336. {
  4337. checkTempStopTransaction(gun_index);
  4338. }
  4339. #endif
  4340. }
  4341. }
  4342. }
  4343. else
  4344. {
  4345. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4346. {
  4347. tempIndex = 2;
  4348. }
  4349. else
  4350. {
  4351. tempIndex = gun_index;
  4352. }
  4353. for (int index = 0; index < AC_QUANTITY; index++)
  4354. {
  4355. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4356. {
  4357. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4358. {
  4359. // Sent unplug message for California pricing logic
  4360. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4361. {
  4362. uint8_t ts[36];
  4363. getNowDatetime(ts);
  4364. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4365. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4366. if(strcmp((char*)dmsVersion, "2.0")==0)
  4367. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4368. else
  4369. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4370. sendUnplugByDataTransferRequest(gun_index);
  4371. interLock.isSentUnplug[gun_index] = 1;
  4372. }
  4373. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4374. {
  4375. interLock.isSentUnplug[gun_index] = 0;
  4376. }
  4377. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4378. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4379. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4380. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4381. {
  4382. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4383. if((access(filenmae,F_OK))!=-1)
  4384. {
  4385. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4386. sprintf(str,"rm -f %s",filenmae);
  4387. system(str);
  4388. }
  4389. }
  4390. }
  4391. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4392. #if 1 // for TempStopTransaction
  4393. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4394. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4395. {
  4396. checkTempStopTransaction(gun_index);
  4397. }
  4398. #endif
  4399. }
  4400. }// END
  4401. }
  4402. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4403. (
  4404. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4405. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4406. )
  4407. )
  4408. {
  4409. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4410. sendStatusNotificationRequest(gun_index);
  4411. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4412. }
  4413. //==============================================
  4414. // TCCI reader status report
  4415. //==============================================
  4416. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4417. {
  4418. reportReaderStatus(gun_index);
  4419. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4420. }
  4421. //==============================================
  4422. // CSU Trigger Smart Charging Profile
  4423. //==============================================
  4424. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4425. {
  4426. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4427. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4428. }
  4429. //==============================================
  4430. // Meter report
  4431. //==============================================
  4432. // Trigger MeterValue
  4433. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4434. {
  4435. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4436. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4437. }
  4438. // Clock-aligned Meter value
  4439. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4440. {
  4441. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4442. reqClockAlignMeter[gun_index] = 0;
  4443. }
  4444. // Sample period MeterValue
  4445. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4446. {
  4447. //check Transaction active
  4448. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4449. {
  4450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4451. {
  4452. tempIndex = ((gun_index==2) ? 1: 0);
  4453. }
  4454. else
  4455. {
  4456. tempIndex = gun_index;
  4457. }
  4458. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4459. {
  4460. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4461. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4462. {
  4463. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4464. {
  4465. reqSampleMeter[gun_index] = 1;
  4466. }
  4467. }
  4468. }// End for CHAdeMO
  4469. }
  4470. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4471. {
  4472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4473. {
  4474. tempIndex = ((gun_index==2) ? 1: 0);
  4475. }
  4476. else
  4477. {
  4478. tempIndex = gun_index;
  4479. }
  4480. for (int index = 0; index < CCS_QUANTITY; index++)
  4481. {
  4482. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4483. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4484. {
  4485. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4486. {
  4487. reqSampleMeter[gun_index] = 1;
  4488. }
  4489. }
  4490. } // End for CCS
  4491. }
  4492. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4493. {
  4494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4495. {
  4496. tempIndex = ((gun_index==2) ? 1: 0);
  4497. }
  4498. else
  4499. {
  4500. tempIndex = gun_index;
  4501. }
  4502. for (int index = 0; index < GB_QUANTITY; index++)
  4503. {
  4504. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4505. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4506. {
  4507. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4508. {
  4509. reqSampleMeter[gun_index] = 1;
  4510. }
  4511. }
  4512. }// End for GB
  4513. }
  4514. else if(gunType[gun_index] == GUN_TYPE_DO)
  4515. {
  4516. tempIndex = gun_index;
  4517. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4518. {
  4519. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4520. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4521. {
  4522. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4523. {
  4524. reqSampleMeter[gun_index] = 1;
  4525. }
  4526. }
  4527. }
  4528. }
  4529. else
  4530. {
  4531. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4532. {
  4533. tempIndex = 2;
  4534. }
  4535. else
  4536. {
  4537. tempIndex = gun_index;
  4538. }
  4539. for (int index = 0; index < AC_QUANTITY; index++)
  4540. {
  4541. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4542. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4543. {
  4544. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4545. {
  4546. reqSampleMeter[gun_index] = 1;
  4547. }
  4548. }
  4549. }//End for AC
  4550. }
  4551. if(reqSampleMeter[gun_index] == 1)
  4552. {
  4553. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4554. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4555. //storeTempStopTransaction(gun_index);
  4556. reqSampleMeter[gun_index] = 0;
  4557. }
  4558. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4559. }
  4560. //==============================================
  4561. // Check Connector reserved
  4562. //==============================================
  4563. //===============================
  4564. // Check if Reserve is expired
  4565. //===============================
  4566. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4567. {
  4568. double diff_t;
  4569. struct tm tp;
  4570. // current time
  4571. time_t t = time(NULL);
  4572. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4573. tp.tm_isdst = -1;
  4574. time_t utc = mktime(&tp);
  4575. diff_t = difftime(utc, t);
  4576. if(diff_t <= 0)
  4577. {
  4578. DEBUG_INFO("reserve expired.\n");
  4579. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4580. }
  4581. }//END OF Check if Reserve is expired
  4582. //==========================================
  4583. // csu trigger FirmwareStatusNotificationReq
  4584. //==========================================
  4585. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4586. {
  4587. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4588. }
  4589. //==========================================
  4590. // csu trigger DiagnosticsStatusNotificationReq
  4591. //==========================================
  4592. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4593. {
  4594. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4595. }
  4596. //==========================================
  4597. // csu trigger CancelReservationConf
  4598. //==========================================
  4599. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4600. {
  4601. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4602. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4603. }
  4604. //==========================================
  4605. // csu trigger ChangeAvailabilityConf
  4606. //==========================================
  4607. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4608. {
  4609. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4610. }
  4611. //==========================================
  4612. // csu trigger UnlockConnectorConf
  4613. //==========================================
  4614. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4615. {
  4616. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4617. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4618. }
  4619. //==========================================
  4620. // csu trigger ReserveNowConf
  4621. //==========================================
  4622. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4623. {
  4624. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4625. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4626. }
  4627. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4628. {
  4629. sendSignCertificateRequest();
  4630. }
  4631. }
  4632. }
  4633. //==========================================
  4634. // send request routine
  4635. //==========================================
  4636. int sendAuthorizeRequest(int gun_index)
  4637. {
  4638. mtrace();
  4639. int result = FAIL;
  4640. char message[100]={0};
  4641. char guid[37];
  4642. char tempdata[65]={0};
  4643. DEBUG_INFO("sendAuthorizeRequest...\n");
  4644. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4645. //Local Authorize
  4646. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4647. {
  4648. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4649. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4650. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4651. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4652. result = PASS;
  4653. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4654. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4655. authorizeRetryTimes = 0;
  4656. return result;
  4657. }
  4658. else if(((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0))||
  4659. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4660. {
  4661. // Query from cache
  4662. DEBUG_INFO("Authorize from cache.\n");
  4663. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4664. // Query from list
  4665. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4666. {
  4667. DEBUG_INFO("Authorize from list.\n");
  4668. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4669. }
  4670. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4671. {
  4672. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4673. {
  4674. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4675. }
  4676. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4677. {
  4678. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4679. }
  4680. if(!GetOcppConnStatus())
  4681. {
  4682. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4683. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4684. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4685. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4686. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4687. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4688. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4689. authorizeRetryTimes = 0;
  4690. return result;
  4691. }
  4692. }
  4693. else
  4694. {
  4695. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4696. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4697. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4698. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4699. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4700. else
  4701. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4702. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4703. result = PASS;
  4704. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4705. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4706. authorizeRetryTimes = 0;
  4707. return result;
  4708. }
  4709. }
  4710. //initialize struct Authorize
  4711. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4712. //get data from shared memory
  4713. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4714. random_uuid(guid);
  4715. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4716. LWS_Send(message);
  4717. sprintf(tempdata, "Authorize,%d", gun_index);
  4718. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4719. {
  4720. result = PASS;
  4721. DEBUG_INFO("Authorize mapItem pass\n");
  4722. }
  4723. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4724. return result;
  4725. }
  4726. int sendBootNotificationRequest(void)
  4727. {
  4728. mtrace();
  4729. int result = FAIL;
  4730. char message[500]={0}, payload[700]={0};
  4731. char guid[37]={0};
  4732. char tempdata[65]={0};
  4733. // Fill BootNotification fields
  4734. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4735. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4736. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4737. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4738. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4739. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4740. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4741. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4742. ShmOCPP16DataPH->ChargeBoxId
  4743. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4744. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4745. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4746. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4747. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4748. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4749. random_uuid(guid);
  4750. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4751. LWS_Send(message);
  4752. sprintf(tempdata, "BootNotification,0");
  4753. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4754. {
  4755. result = PASS;
  4756. }
  4757. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4758. strcpy(queuedata,message);
  4759. return result;
  4760. }
  4761. int sendDataTransferRequest(int gun_index)
  4762. {
  4763. mtrace();
  4764. char message[1000]={0};
  4765. char guid[37]={0};
  4766. char tempdata[65]={0};
  4767. int result = FAIL;
  4768. random_uuid(guid);
  4769. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4770. MESSAGE_TYPE_CALL,
  4771. guid,
  4772. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4773. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4774. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4775. LWS_Send(message);
  4776. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4777. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4778. {
  4779. result = PASS;
  4780. DEBUG_INFO("DataTransfer mapItem pass\n");
  4781. }
  4782. return result;
  4783. }
  4784. int sendUnplugByDataTransferRequest(int gun_index)
  4785. {
  4786. mtrace();
  4787. char message[1000]={0};
  4788. char guid[37]={0};
  4789. char tempdata[65]={0};
  4790. int result = FAIL;
  4791. random_uuid(guid);
  4792. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4793. (gun_index+1),
  4794. MESSAGE_TYPE_CALL,
  4795. guid,
  4796. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4797. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4798. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4799. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4800. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4801. {
  4802. result = PASS;
  4803. DEBUG_INFO("DataTransfer mapItem pass\n");
  4804. }
  4805. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  4806. return result;
  4807. }
  4808. int sendDiagnosticsStatusNotificationRequest(char *status)
  4809. {
  4810. mtrace();
  4811. int result = FAIL;
  4812. char message[110]={0};
  4813. char guid[37]={0};
  4814. char tempdata[65]={0};
  4815. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4816. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4817. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4818. random_uuid(guid);
  4819. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4820. LWS_SendNow(message);
  4821. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4822. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4823. {
  4824. result = PASS;
  4825. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4826. }
  4827. //#ifdef SystemLogMessage
  4828. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4829. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4830. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4831. //#endif
  4832. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4833. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4834. //record status
  4835. if(strcmp(status,"Idle")==0)
  4836. {
  4837. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4838. }
  4839. else if(strcmp(status,"Uploaded")==0)
  4840. {
  4841. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4842. }
  4843. else if(strcmp(status,"UploadFailed")==0)
  4844. {
  4845. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4846. }
  4847. else if(strcmp(status,"Uploading")==0)
  4848. {
  4849. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4850. }
  4851. return result;
  4852. }
  4853. int sendFirmwareStatusNotificationRequest(char *status)
  4854. {
  4855. mtrace();
  4856. int result = FAIL;
  4857. char message[110]={0};
  4858. char guid[37]={0};
  4859. char tempdata[65]={0};
  4860. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4861. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4862. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4863. random_uuid(guid);
  4864. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4865. LWS_SendNow(message);
  4866. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4867. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4868. {
  4869. result = PASS;
  4870. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4871. }
  4872. //#ifdef SystemLogMessage
  4873. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4874. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4875. //#endif
  4876. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4877. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4878. //record status
  4879. if(strcmp(status,"Downloaded")==0)
  4880. {
  4881. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4882. }
  4883. else if(strcmp(status,"DownloadFailed")==0)
  4884. {
  4885. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4886. }
  4887. else if(strcmp(status,"Downloading")==0)
  4888. {
  4889. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4890. }
  4891. else if(strcmp(status,"Idle")==0)
  4892. {
  4893. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4894. }
  4895. else if(strcmp(status,"InstallationFailed")==0)
  4896. {
  4897. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4898. }
  4899. else if(strcmp(status,"Installing")==0)
  4900. {
  4901. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4902. }
  4903. else if(strcmp(status,"Installed")==0)
  4904. {
  4905. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4906. }
  4907. return result;
  4908. }
  4909. int sendHeartbeatRequest(int gun_index)
  4910. {
  4911. mtrace();
  4912. int result = FAIL;
  4913. char message[80]={0};
  4914. char guid[37]={0};
  4915. char tempdata[65]={0};
  4916. random_uuid(guid);
  4917. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4918. , MESSAGE_TYPE_CALL
  4919. , guid );
  4920. LWS_Send(message);
  4921. sprintf(tempdata, "Heartbeat,%d", 0);
  4922. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4923. {
  4924. result = PASS;
  4925. }
  4926. return result;
  4927. }
  4928. int sendStartTransactionRequest(int gun_index)
  4929. {
  4930. mtrace();
  4931. int result = FAIL;
  4932. char message[250]={0};
  4933. char guid[37]={0};
  4934. struct timeval tmnow;
  4935. struct tm *tm;
  4936. char buf[28];//, usec_buf[6];
  4937. char tempdata[65]={0};
  4938. int tempIndex = 0;
  4939. DEBUG_INFO("sendStartTransactionRequest...\n");
  4940. gettimeofday(&tmnow, NULL);
  4941. time_t t;
  4942. t = time(NULL);
  4943. /*UTC time and date*/
  4944. tm = gmtime(&t);
  4945. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4946. #if 0 // remove temporally
  4947. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4948. strcat(buf,".");
  4949. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4950. strcat(buf,usec_buf);
  4951. #endif
  4952. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4953. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4954. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4955. // clear StartTransaction Response
  4956. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4957. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4958. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4959. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4960. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4961. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4962. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4963. {
  4964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4965. {
  4966. tempIndex = ((gun_index==2) ? 1: 0);
  4967. }
  4968. else
  4969. {
  4970. tempIndex = gun_index;
  4971. }
  4972. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4973. {
  4974. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4975. {
  4976. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4977. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4978. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4979. }
  4980. }
  4981. }
  4982. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4983. {
  4984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4985. {
  4986. tempIndex = ((gun_index==2) ? 1: 0);
  4987. }
  4988. else
  4989. {
  4990. tempIndex = gun_index;
  4991. }
  4992. for (int index = 0; index < CCS_QUANTITY; index++)
  4993. {
  4994. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4995. {
  4996. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4997. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4998. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4999. }
  5000. }
  5001. }
  5002. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5003. {
  5004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5005. {
  5006. tempIndex = ((gun_index==2) ? 1: 0);
  5007. }
  5008. else
  5009. {
  5010. tempIndex = gun_index;
  5011. }
  5012. for (int index = 0; index < GB_QUANTITY; index++)
  5013. {
  5014. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5015. {
  5016. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5017. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5018. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5019. }
  5020. }
  5021. }
  5022. else if(gunType[gun_index] == GUN_TYPE_DO)
  5023. {
  5024. tempIndex = gun_index;
  5025. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5026. {
  5027. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5028. {
  5029. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5030. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5031. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5032. }
  5033. }
  5034. }
  5035. else
  5036. {
  5037. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5038. {
  5039. tempIndex = 2;
  5040. }
  5041. else
  5042. {
  5043. tempIndex = gun_index;
  5044. }
  5045. for (int index = 0; index < AC_QUANTITY; index++)
  5046. {
  5047. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5048. {
  5049. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5050. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5051. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5052. }
  5053. }
  5054. }
  5055. random_uuid(guid);
  5056. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5057. {
  5058. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5059. , gun_index +1
  5060. , MESSAGE_TYPE_CALL
  5061. , guid
  5062. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5063. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5064. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5065. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5066. }
  5067. else
  5068. {
  5069. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5070. , gun_index +1
  5071. , MESSAGE_TYPE_CALL
  5072. , guid
  5073. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5074. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5075. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5076. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  5077. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5078. }
  5079. #if 1
  5080. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5081. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5082. {
  5083. result = PASS;
  5084. }
  5085. #endif
  5086. strcpy(queuedata, message);
  5087. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5088. OCPP_insert_transaction_msg(YES, queuedata);
  5089. return result;
  5090. }
  5091. int sendStatusNotificationRequest(int gun_index)
  5092. {
  5093. mtrace();
  5094. int result = FAIL;
  5095. char message[600]={0};
  5096. char guid[37];
  5097. int currentStatus = 0;
  5098. struct timeval tmnow;
  5099. struct tm *tm;
  5100. char buf[28];//, usec_buf[6];
  5101. char tempdata[65]={0};
  5102. int tempIndex = 0;
  5103. uint8_t isStateChanged = TRUE;
  5104. uint8_t isContentIllegal = TRUE;
  5105. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5106. gettimeofday(&tmnow, NULL);
  5107. time_t t;
  5108. t = time(NULL);
  5109. /*UTC time and date*/
  5110. tm = gmtime(&t);
  5111. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5112. #if 0 // remove temporally
  5113. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5114. strcat(buf,".");
  5115. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5116. strcat(buf,usec_buf);
  5117. #endif
  5118. //printf("%s",buf);
  5119. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5120. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5121. // it's option
  5122. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5123. /*
  5124. enum _SYSTEM_STATUS
  5125. {
  5126. S_BOOTING = 0,
  5127. S_IDLE, = 1
  5128. S_AUTHORIZING, =2
  5129. S_REASSIGN_CHECK, =3
  5130. S_REASSIGN, =4
  5131. S_PRECHARGE, =5
  5132. S_PREPARING_FOR_EV, =6
  5133. S_PREPARING_FOR_EVSE, =7
  5134. S_CHARGING, =8
  5135. S_TERMINATING, =9
  5136. S_COMPLETE, =10
  5137. S_ALARM, =11
  5138. S_FAULT =12
  5139. }
  5140. */
  5141. //check Transaction active
  5142. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5143. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5144. {
  5145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5146. {
  5147. tempIndex = ((gun_index==2) ? 1: 0);
  5148. }
  5149. else
  5150. {
  5151. tempIndex = gun_index;
  5152. }
  5153. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5154. {
  5155. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5156. {
  5157. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5158. {
  5159. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5160. {
  5161. currentStatus = Preparing; //OCPP Status: Preparing
  5162. }
  5163. else
  5164. {
  5165. currentStatus = Available; //OCPP Status: Available
  5166. }
  5167. }
  5168. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5169. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5170. ) //S_PRECHARGE
  5171. {
  5172. currentStatus = Preparing; //OCPP Status: Preparing
  5173. }
  5174. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5175. {
  5176. currentStatus = Charging; //OCPP Status: Charging
  5177. }
  5178. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5179. {
  5180. currentStatus = Finishing; //OCPP Status: Finishing
  5181. }
  5182. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5183. {
  5184. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5185. }
  5186. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5187. {
  5188. currentStatus = Unavailable; //OCPP Status: Unavailable
  5189. }
  5190. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5191. {
  5192. currentStatus = Faulted; //OCPP Status: Faulted
  5193. }
  5194. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5195. {
  5196. currentStatus = Reserved; //OCPP Status: Reserved
  5197. }
  5198. } //end of the same index
  5199. }//end of for CHAdeMO_QUANTITY
  5200. }
  5201. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5202. {
  5203. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5204. {
  5205. tempIndex = ((gun_index==2) ? 1: 0);
  5206. }
  5207. else
  5208. {
  5209. tempIndex = gun_index;
  5210. }
  5211. for (int index = 0; index < CCS_QUANTITY; index++)
  5212. {
  5213. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5214. {
  5215. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5216. {
  5217. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5218. {
  5219. currentStatus = Preparing; //OCPP Status: Preparing
  5220. }
  5221. else
  5222. {
  5223. currentStatus = Available; //OCPP Status: Available
  5224. }
  5225. }
  5226. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5227. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5228. ) //S_PRECHARGE
  5229. {
  5230. currentStatus = Preparing; //OCPP Status: Preparing
  5231. }
  5232. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5233. {
  5234. currentStatus = Charging; //OCPP Status: Charging
  5235. }
  5236. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5237. {
  5238. currentStatus = Finishing; //OCPP Status: Finishing
  5239. }
  5240. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5241. {
  5242. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5243. }
  5244. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5245. {
  5246. currentStatus = Unavailable; //OCPP Status : Unavailable
  5247. }
  5248. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5249. {
  5250. currentStatus = Faulted; //OCPP Status: Faulted
  5251. }
  5252. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5253. {
  5254. currentStatus = Reserved; //OCPP Status: Reserved
  5255. }
  5256. } //end of the same index
  5257. } // end of for CCS_QUANTITY
  5258. }
  5259. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5260. {
  5261. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5262. {
  5263. tempIndex = ((gun_index==2) ? 1: 0);
  5264. }
  5265. else
  5266. {
  5267. tempIndex = gun_index;
  5268. }
  5269. for (int index = 0; index < GB_QUANTITY; index++)
  5270. {
  5271. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5272. {
  5273. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5274. {
  5275. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5276. {
  5277. currentStatus = Preparing; //OCPP Status: Preparing
  5278. }
  5279. else
  5280. {
  5281. currentStatus = Available; //OCPP Status: Available
  5282. }
  5283. }
  5284. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5285. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5286. ) //S_PRECHARGE
  5287. {
  5288. currentStatus = Preparing; //OCPP Status: Preparing
  5289. }
  5290. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5291. {
  5292. currentStatus = Charging; //OCPP Status: Charging
  5293. }
  5294. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5295. {
  5296. currentStatus = Finishing; //OCPP Status: Finishing
  5297. }
  5298. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5299. {
  5300. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5301. }
  5302. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5303. {
  5304. currentStatus = Unavailable; //OCPP Status: Unavailable
  5305. }
  5306. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5307. {
  5308. currentStatus = Faulted; //OCPP Status: Faulted
  5309. }
  5310. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5311. {
  5312. currentStatus = Reserved; //OCPP Status: Reserved
  5313. }
  5314. } //end of the same index
  5315. } // end of for GB_QUANTITY
  5316. }
  5317. else if(gunType[gun_index] == GUN_TYPE_DO)
  5318. {
  5319. tempIndex = gun_index;
  5320. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5321. {
  5322. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5323. {
  5324. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5325. {
  5326. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5327. {
  5328. currentStatus = Preparing; //OCPP Status: Preparing
  5329. }
  5330. else
  5331. {
  5332. currentStatus = Available; //OCPP Status: Available
  5333. }
  5334. }
  5335. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5336. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5337. ) //S_PRECHARGE
  5338. {
  5339. currentStatus = Preparing; //OCPP Status: Preparing
  5340. }
  5341. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5342. {
  5343. currentStatus = Charging; //OCPP Status: Charging
  5344. }
  5345. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5346. {
  5347. currentStatus = Finishing; //OCPP Status: Finishing
  5348. }
  5349. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5350. {
  5351. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5352. }
  5353. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5354. {
  5355. currentStatus = Unavailable; //OCPP Status: Unavailable
  5356. }
  5357. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5358. {
  5359. currentStatus = Faulted; //OCPP Status: Faulted
  5360. }
  5361. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5362. {
  5363. currentStatus = Reserved; //OCPP Status: Reserved
  5364. }
  5365. } //end of the same index
  5366. }
  5367. }
  5368. else
  5369. {
  5370. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5371. {
  5372. tempIndex = 2;
  5373. }
  5374. else
  5375. {
  5376. tempIndex = gun_index;
  5377. }
  5378. for (int index = 0; index < AC_QUANTITY; index++)
  5379. {
  5380. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5381. {
  5382. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5383. {
  5384. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  5385. {
  5386. currentStatus = Preparing; //OCPP Status: Preparing
  5387. }
  5388. else
  5389. {
  5390. currentStatus = Available; //OCPP Status: Available
  5391. }
  5392. }
  5393. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5394. {
  5395. currentStatus = Preparing; //OCPP Status: Preparing
  5396. }
  5397. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5398. {
  5399. currentStatus = Charging; //OCPP Status: Charging
  5400. }
  5401. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5402. {
  5403. currentStatus = Finishing; //OCPP Status: Finishing
  5404. }
  5405. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5406. {
  5407. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5408. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5409. else
  5410. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5411. }
  5412. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5413. {
  5414. currentStatus = Unavailable; //OCPP Status: Unavailable
  5415. }
  5416. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5417. {
  5418. currentStatus = Faulted; //OCPP Status: Faulted
  5419. }
  5420. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5421. {
  5422. currentStatus = Reserved; //OCPP Status: Reserved
  5423. }
  5424. }//end of the same index
  5425. }//end of for AC_QUANTITY
  5426. }
  5427. //it's option
  5428. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5429. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5430. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5431. {
  5432. isStateChanged = FALSE;
  5433. }
  5434. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5435. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5436. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5437. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5438. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5439. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5440. isContentIllegal = TRUE;
  5441. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5442. {
  5443. if(strcmp((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5444. {
  5445. isContentIllegal = FALSE;
  5446. break;
  5447. }
  5448. }
  5449. if(isContentIllegal)
  5450. {
  5451. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5452. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5453. }
  5454. random_uuid(guid);
  5455. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5456. , MESSAGE_TYPE_CALL
  5457. , guid
  5458. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5459. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5460. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5461. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5462. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5463. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5464. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5465. if((server_sign == TRUE) && isStateChanged)
  5466. {
  5467. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5468. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5469. LWS_Send(message);
  5470. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5471. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5472. {
  5473. //DEBUG_ERROR("statusNotification mapitem pass");
  5474. result = PASS;
  5475. }
  5476. }
  5477. else
  5478. {
  5479. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5480. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5481. result = PASS;
  5482. }
  5483. return result;
  5484. }
  5485. int sendStopTransactionRequest(int gun_index)
  5486. {
  5487. mtrace();
  5488. int result = FAIL;
  5489. //char message[1500]={0};
  5490. char guid[37]={0};
  5491. char tempdata[65]={0};
  5492. int tempIndex = 0;
  5493. char TempStopTransaction[256];
  5494. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5495. //int idx_sample=0;
  5496. DEBUG_INFO("sendStopTransactionRequest \n");
  5497. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5498. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5499. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5500. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5501. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5502. {
  5503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5504. {
  5505. tempIndex = ((gun_index==2) ? 1: 0);
  5506. }
  5507. else
  5508. {
  5509. tempIndex = gun_index;
  5510. }
  5511. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5512. {
  5513. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5514. {
  5515. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5516. }
  5517. }// END OF CHAdeMO_QUANTITY
  5518. }
  5519. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5520. {
  5521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5522. {
  5523. tempIndex = ((gun_index==2) ? 1: 0);
  5524. }
  5525. else
  5526. {
  5527. tempIndex = gun_index;
  5528. }
  5529. for (int index = 0; index < CCS_QUANTITY; index++)
  5530. {
  5531. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5532. {
  5533. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5534. }
  5535. }// END OF CCS_QUANTITY
  5536. }
  5537. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5538. {
  5539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5540. {
  5541. tempIndex = ((gun_index==2) ? 1: 0);
  5542. }
  5543. else
  5544. {
  5545. tempIndex = gun_index;
  5546. }
  5547. for (int index = 0; index < GB_QUANTITY; index++)
  5548. {
  5549. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5550. {
  5551. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5552. }
  5553. }// END OF GB_QUANTITY
  5554. }
  5555. else if(gunType[gun_index] == GUN_TYPE_DO)
  5556. {
  5557. tempIndex = gun_index;
  5558. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5559. {
  5560. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5561. {
  5562. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5563. }
  5564. }// END OF GB_QUANTITY
  5565. }
  5566. else
  5567. {
  5568. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5569. {
  5570. tempIndex = 2;
  5571. }
  5572. else
  5573. {
  5574. tempIndex = gun_index;
  5575. }
  5576. for (int index = 0; index < AC_QUANTITY; index++)
  5577. {
  5578. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5579. {
  5580. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5581. }
  5582. }// END OF AC_QUANTITY
  5583. }
  5584. //====================================== Stop Transaction Time =====================================================
  5585. struct timeval tmnow;
  5586. struct tm *tm;
  5587. char buf[28];//, usec_buf[6];
  5588. gettimeofday(&tmnow, NULL);
  5589. time_t t;
  5590. t = time(NULL);
  5591. /*UTC time and date*/
  5592. tm = gmtime(&t);
  5593. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5594. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5595. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5596. random_uuid(guid);
  5597. /***********************************transactionData******************************************************/
  5598. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5599. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5600. //=================================
  5601. // Transaction_Begin
  5602. //=================================
  5603. //=================================
  5604. // Transaction_End
  5605. //=================================
  5606. // ================================= Current.Import L1 ===============================================
  5607. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5608. {
  5609. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5610. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5611. {
  5612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5613. {
  5614. tempIndex = ((gun_index==2) ? 1: 0);
  5615. }
  5616. else
  5617. {
  5618. tempIndex = gun_index;
  5619. }
  5620. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5621. {
  5622. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5623. {
  5624. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5625. }
  5626. }// End of for CHAdeMO_QUANTITY
  5627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5628. }
  5629. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5630. {
  5631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5632. {
  5633. tempIndex = ((gun_index==2) ? 1: 0);
  5634. }
  5635. else
  5636. {
  5637. tempIndex = gun_index;
  5638. }
  5639. for (int index = 0; index < CCS_QUANTITY; index++)
  5640. {
  5641. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5642. {
  5643. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5644. }
  5645. }// End of for CCS_QUANTITY
  5646. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5647. }
  5648. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5649. {
  5650. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5651. {
  5652. tempIndex = ((gun_index==2) ? 1: 0);
  5653. }
  5654. else
  5655. {
  5656. tempIndex = gun_index;
  5657. }
  5658. for (int index = 0; index < GB_QUANTITY; index++)
  5659. {
  5660. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5661. {
  5662. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5663. }
  5664. }// End of for GB_QUANTITY
  5665. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5666. }
  5667. else if(gunType[gun_index] == GUN_TYPE_DO)
  5668. {
  5669. tempIndex = gun_index;
  5670. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5671. {
  5672. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5673. {
  5674. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5675. }
  5676. }
  5677. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5678. }
  5679. else
  5680. {
  5681. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5682. {
  5683. tempIndex = 2;
  5684. }
  5685. else
  5686. {
  5687. tempIndex = gun_index;
  5688. }
  5689. for (int index = 0; index < AC_QUANTITY; index++)
  5690. {
  5691. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5692. {
  5693. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5694. }
  5695. }// End of for AC_QUANTITY
  5696. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5697. }
  5698. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5699. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5700. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5701. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5702. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5703. }
  5704. // ================================= Energy.Active.Import.Interval ==============================================
  5705. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5706. {
  5707. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5708. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5709. {
  5710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5711. {
  5712. tempIndex = ((gun_index==2) ? 1: 0);
  5713. }
  5714. else
  5715. {
  5716. tempIndex = gun_index;
  5717. }
  5718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5719. {
  5720. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5721. {
  5722. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5723. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5724. }
  5725. }// END OF CHAdeMO_QUANTITY
  5726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5727. }
  5728. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5729. {
  5730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5731. {
  5732. tempIndex = ((gun_index==2) ? 1: 0);
  5733. }
  5734. else
  5735. {
  5736. tempIndex = gun_index;
  5737. }
  5738. for (int index = 0; index < CCS_QUANTITY; index++)
  5739. {
  5740. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5741. {
  5742. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5743. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5744. }
  5745. }// END OF CCS_QUANTITY
  5746. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5747. }
  5748. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5749. {
  5750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5751. {
  5752. tempIndex = ((gun_index==2) ? 1: 0);
  5753. }
  5754. else
  5755. {
  5756. tempIndex = gun_index;
  5757. }
  5758. for (int index = 0; index < GB_QUANTITY; index++)
  5759. {
  5760. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5761. {
  5762. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5763. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5764. }
  5765. }// END OF GB_QUANTITY
  5766. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5767. }
  5768. else if(gunType[gun_index] == GUN_TYPE_DO)
  5769. {
  5770. tempIndex = gun_index;
  5771. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5772. {
  5773. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5774. {
  5775. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5776. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5777. }
  5778. }
  5779. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5780. }
  5781. else
  5782. {
  5783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5784. {
  5785. tempIndex = 2;
  5786. }
  5787. else
  5788. {
  5789. tempIndex = gun_index;
  5790. }
  5791. for (int index = 0; index < AC_QUANTITY; index++)
  5792. {
  5793. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5794. {
  5795. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5796. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5797. }
  5798. }// END OF AC_QUANTITY
  5799. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5800. }
  5801. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5803. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5804. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5806. }
  5807. //=================================== Power.Active.Import ==================================================
  5808. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5809. {
  5810. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5811. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5812. {
  5813. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5814. {
  5815. tempIndex = ((gun_index==2) ? 1: 0);
  5816. }
  5817. else
  5818. {
  5819. tempIndex = gun_index;
  5820. }
  5821. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5822. {
  5823. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5824. {
  5825. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5826. }
  5827. } // End for CHAdeMO_QUANTITY
  5828. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5829. }
  5830. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5831. {
  5832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5833. {
  5834. tempIndex = ((gun_index==2) ? 1: 0);
  5835. }
  5836. else
  5837. {
  5838. tempIndex = gun_index;
  5839. }
  5840. for (int index = 0; index < CCS_QUANTITY; index++)
  5841. {
  5842. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5843. {
  5844. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5845. }
  5846. } // END for CCS_QUANTITY
  5847. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5848. }
  5849. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5850. {
  5851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5852. {
  5853. tempIndex = ((gun_index==2) ? 1: 0);
  5854. }
  5855. else
  5856. {
  5857. tempIndex = gun_index;
  5858. }
  5859. for (int index = 0; index < GB_QUANTITY; index++)
  5860. {
  5861. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5862. {
  5863. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5864. }
  5865. }// END for GB_QUANTITY
  5866. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5867. }
  5868. else if(gunType[gun_index] == GUN_TYPE_DO)
  5869. {
  5870. tempIndex = gun_index;
  5871. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5872. {
  5873. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5874. {
  5875. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5876. }
  5877. }
  5878. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5879. }
  5880. else
  5881. {
  5882. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5883. {
  5884. tempIndex = 2;
  5885. }
  5886. else
  5887. {
  5888. tempIndex = gun_index;
  5889. }
  5890. for (int index = 0; index < AC_QUANTITY; index++)
  5891. {
  5892. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5893. {
  5894. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5895. }
  5896. } // END for AC_QUANTITY
  5897. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5898. }
  5899. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5900. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5901. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5902. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5903. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5904. }
  5905. //============================ Voltage L1 ====================================
  5906. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5907. {
  5908. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5909. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5910. {
  5911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5912. {
  5913. tempIndex = ((gun_index==2) ? 1: 0);
  5914. }
  5915. else
  5916. {
  5917. tempIndex = gun_index;
  5918. }
  5919. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5920. {
  5921. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5922. {
  5923. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5924. }
  5925. } // END OF FOR CHAdeMO_QUANTITY
  5926. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5927. }
  5928. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5929. {
  5930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5931. {
  5932. tempIndex = ((gun_index==2) ? 1: 0);
  5933. }
  5934. else
  5935. {
  5936. tempIndex = gun_index;
  5937. }
  5938. for (int index = 0; index < CCS_QUANTITY; index++)
  5939. {
  5940. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5941. {
  5942. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5943. }
  5944. } // END OF FOR CCS_QUANTITY
  5945. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5946. }
  5947. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5948. {
  5949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5950. {
  5951. tempIndex = ((gun_index==2) ? 1: 0);
  5952. }
  5953. else
  5954. {
  5955. tempIndex = gun_index;
  5956. }
  5957. for (int index = 0; index < GB_QUANTITY; index++)
  5958. {
  5959. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5960. {
  5961. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5962. }
  5963. } // END OF FOR GB_QUANTITY
  5964. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5965. }
  5966. else if(gunType[gun_index] == GUN_TYPE_DO)
  5967. {
  5968. tempIndex = gun_index;
  5969. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5970. {
  5971. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5972. {
  5973. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5974. }
  5975. }
  5976. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5977. }
  5978. else
  5979. {
  5980. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5981. {
  5982. tempIndex = 2;
  5983. }
  5984. else
  5985. {
  5986. tempIndex = gun_index;
  5987. }
  5988. for (int index = 0; index < AC_QUANTITY; index++)
  5989. {
  5990. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5991. {
  5992. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5993. }
  5994. } // END OF FOR AC_QUANTITY
  5995. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5996. }
  5997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5998. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5999. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6000. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6002. }
  6003. //====================== End SoC ================================
  6004. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6005. {
  6006. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6007. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6008. {
  6009. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6010. {
  6011. tempIndex = ((gun_index==2) ? 1: 0);
  6012. }
  6013. else
  6014. {
  6015. tempIndex = gun_index;
  6016. }
  6017. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6018. {
  6019. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6020. {
  6021. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6022. {
  6023. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6024. }
  6025. }
  6026. }
  6027. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6028. {
  6029. for (int index = 0; index < CCS_QUANTITY; index++)
  6030. {
  6031. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6032. {
  6033. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6034. }
  6035. }
  6036. }
  6037. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6038. {
  6039. for (int index = 0; index < GB_QUANTITY; index++)
  6040. {
  6041. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6042. {
  6043. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6044. }
  6045. }
  6046. }
  6047. else if(gunType[gun_index] == GUN_TYPE_DO)
  6048. {
  6049. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6050. {
  6051. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6052. {
  6053. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6054. }
  6055. }
  6056. }
  6057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6059. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6061. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6062. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6063. } // END FOR DC CASE
  6064. }
  6065. // ================================= Current.Import L2 ===============================================
  6066. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6067. {
  6068. // AC 3 phse L2 current
  6069. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6070. {
  6071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6072. {
  6073. tempIndex = 2;
  6074. }
  6075. else
  6076. {
  6077. tempIndex = gun_index;
  6078. }
  6079. for (int index = 0; index < AC_QUANTITY; index++)
  6080. {
  6081. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6082. {
  6083. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6084. }
  6085. }// End of for AC_QUANTITY
  6086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6087. }
  6088. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6089. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6090. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6091. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6092. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6093. }
  6094. // ================================= Current.Import L3 ===============================================
  6095. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6096. {
  6097. // AC 3 phse L3 current
  6098. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6099. {
  6100. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6101. {
  6102. tempIndex = 2;
  6103. }
  6104. else
  6105. {
  6106. tempIndex = gun_index;
  6107. }
  6108. for (int index = 0; index < AC_QUANTITY; index++)
  6109. {
  6110. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6111. {
  6112. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6113. }
  6114. }// End of for AC_QUANTITY
  6115. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6116. }
  6117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6121. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6122. }
  6123. //============================ Voltage L2 ====================================
  6124. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6125. {
  6126. // AC 3 phse L2 voltage
  6127. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6128. {
  6129. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6130. {
  6131. tempIndex = 2;
  6132. }
  6133. else
  6134. {
  6135. tempIndex = gun_index;
  6136. }
  6137. for (int index = 0; index < AC_QUANTITY; index++)
  6138. {
  6139. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6140. {
  6141. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6142. }
  6143. } // END OF FOR AC_QUANTITY
  6144. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6145. }
  6146. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6147. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6148. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6149. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6150. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6151. }
  6152. //============================ Voltage L3 ====================================
  6153. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6154. {
  6155. // AC 3 phse L3 voltage
  6156. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6157. {
  6158. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6159. {
  6160. tempIndex = 2;
  6161. }
  6162. else
  6163. {
  6164. tempIndex = gun_index;
  6165. }
  6166. for (int index = 0; index < AC_QUANTITY; index++)
  6167. {
  6168. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6169. {
  6170. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6171. }
  6172. } // END OF FOR AC_QUANTITY
  6173. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6174. }
  6175. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6176. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6177. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6178. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6179. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6180. }
  6181. //====================== Start SoC ================================
  6182. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6183. {
  6184. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6185. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6186. {
  6187. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6188. {
  6189. tempIndex = ((gun_index==2) ? 1: 0);
  6190. }
  6191. else
  6192. {
  6193. tempIndex = gun_index;
  6194. }
  6195. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6196. {
  6197. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6198. {
  6199. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6200. {
  6201. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6202. }
  6203. }
  6204. }
  6205. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6206. {
  6207. for (int index = 0; index < CCS_QUANTITY; index++)
  6208. {
  6209. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6210. {
  6211. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6212. }
  6213. }
  6214. }
  6215. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6216. {
  6217. for (int index = 0; index < GB_QUANTITY; index++)
  6218. {
  6219. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6220. {
  6221. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6222. }
  6223. }
  6224. }
  6225. else if(gunType[gun_index] == GUN_TYPE_DO)
  6226. {
  6227. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6228. {
  6229. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6230. {
  6231. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6232. }
  6233. }
  6234. }
  6235. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6236. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6237. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6238. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6239. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6240. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6241. } // END FOR DC CASE
  6242. }
  6243. //================================================ Message create ====================================================
  6244. json_object *StopTransaction = json_object_new_object();
  6245. json_object *transactionDatas = json_object_new_array();
  6246. json_object *sampledValues = json_object_new_array();
  6247. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6248. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6249. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6250. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6251. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6252. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6253. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6254. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6255. {
  6256. json_object *transactionData = json_object_new_object();
  6257. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6258. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6259. {
  6260. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6261. {
  6262. json_object *sampledValue = json_object_new_object();
  6263. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6264. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6265. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6266. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6267. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6268. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6269. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6270. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6271. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6272. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6273. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6274. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6275. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6276. json_object_array_add(sampledValues, sampledValue);
  6277. }
  6278. }
  6279. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6280. json_object_array_add(transactionDatas, transactionData);
  6281. }
  6282. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6283. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6284. ,MESSAGE_TYPE_CALL
  6285. ,guid
  6286. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6287. json_object_put(StopTransaction);
  6288. #if 1 // for TempStopTransaction
  6289. //Delete TempStopTransaction
  6290. if((access(TempStopTransaction,F_OK))!=-1)
  6291. {
  6292. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6293. }
  6294. #endif
  6295. #if 1
  6296. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6297. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6298. {
  6299. result = PASS;
  6300. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6301. }
  6302. #endif
  6303. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6304. OCPP_insert_transaction_msg(NO, queuedata);
  6305. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6306. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6307. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6308. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6309. {
  6310. //SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6311. }
  6312. //for test
  6313. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6314. return result;
  6315. }
  6316. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6317. {
  6318. mtrace();
  6319. int result = FAIL;
  6320. char guid[37]={0};
  6321. char tempdata[65]={0};
  6322. int tempIndex = 0;
  6323. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6324. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6325. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6326. //set value
  6327. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6328. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6329. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6330. -1);
  6331. random_uuid(guid);
  6332. //UTC Date time
  6333. struct timeval tmnow;
  6334. struct tm *tm;
  6335. char buf[28];//, usec_buf[6];
  6336. gettimeofday(&tmnow, NULL);
  6337. time_t t;
  6338. t = time(NULL);
  6339. /*UTC time and date*/
  6340. tm = gmtime(&t);
  6341. if(dataType == ReadingContext_Sample_Clock)
  6342. {
  6343. struct tm *tmTarget;
  6344. struct timeb tbTarget;
  6345. tbTarget.time = mktime(tm);
  6346. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6347. tmTarget = gmtime(&tbTarget.time);
  6348. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6349. }
  6350. else
  6351. {
  6352. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6353. }
  6354. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6355. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6356. //********************************(1)Current.Import L1************************************************/
  6357. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6358. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6359. (dataType == ReadingContext_Trigger))
  6360. {
  6361. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6362. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6363. {
  6364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6365. {
  6366. tempIndex = ((gun_index==2) ? 1: 0);
  6367. }
  6368. else
  6369. {
  6370. tempIndex = gun_index;
  6371. }
  6372. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6373. {
  6374. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6375. {
  6376. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6377. }
  6378. }
  6379. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6380. }
  6381. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6382. {
  6383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6384. {
  6385. tempIndex = ((gun_index==2) ? 1: 0);
  6386. }
  6387. else
  6388. {
  6389. tempIndex = gun_index;
  6390. }
  6391. for (int index = 0; index < CCS_QUANTITY; index++)
  6392. {
  6393. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6394. {
  6395. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6396. }
  6397. }
  6398. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6399. }
  6400. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6401. {
  6402. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6403. {
  6404. tempIndex = ((gun_index==2) ? 1: 0);
  6405. }
  6406. else
  6407. {
  6408. tempIndex = gun_index;
  6409. }
  6410. for (int index = 0; index < GB_QUANTITY; index++)
  6411. {
  6412. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6413. {
  6414. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6415. }
  6416. }
  6417. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6418. }
  6419. else if(gunType[gun_index] == GUN_TYPE_DO)
  6420. {
  6421. tempIndex = gun_index;
  6422. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6423. {
  6424. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6425. {
  6426. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6427. }
  6428. }
  6429. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6430. }
  6431. else
  6432. {
  6433. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6434. {
  6435. tempIndex = 2;
  6436. }
  6437. else
  6438. {
  6439. tempIndex = gun_index;
  6440. }
  6441. for (int index = 0; index < AC_QUANTITY; index++)
  6442. {
  6443. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6444. {
  6445. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6446. }
  6447. }
  6448. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6449. }
  6450. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6452. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6453. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6454. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6455. }
  6456. //********************************(2)Energy.Active.Import.Register ************************************************/
  6457. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6458. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6459. (dataType == ReadingContext_Trigger))
  6460. {
  6461. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6462. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6463. {
  6464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6465. {
  6466. tempIndex = ((gun_index==2) ? 1: 0);
  6467. }
  6468. else
  6469. {
  6470. tempIndex = gun_index;
  6471. }
  6472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6473. {
  6474. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6475. {
  6476. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6477. }
  6478. }
  6479. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6480. }
  6481. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6482. {
  6483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6484. {
  6485. tempIndex = ((gun_index==2) ? 1: 0);
  6486. }
  6487. else
  6488. {
  6489. tempIndex = gun_index;
  6490. }
  6491. for (int index = 0; index < CCS_QUANTITY; index++)
  6492. {
  6493. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6494. {
  6495. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6496. }
  6497. }
  6498. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6499. }
  6500. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6501. {
  6502. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6503. {
  6504. tempIndex = ((gun_index==2) ? 1: 0);
  6505. }
  6506. else
  6507. {
  6508. tempIndex = gun_index;
  6509. }
  6510. for (int index = 0; index < GB_QUANTITY; index++)
  6511. {
  6512. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6513. {
  6514. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6515. }
  6516. }
  6517. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6518. }
  6519. else if(gunType[gun_index] == GUN_TYPE_DO)
  6520. {
  6521. tempIndex = gun_index;
  6522. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6523. {
  6524. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6525. {
  6526. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6527. }
  6528. }
  6529. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6530. }
  6531. else
  6532. {
  6533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6534. {
  6535. tempIndex = 2;
  6536. }
  6537. else
  6538. {
  6539. tempIndex = gun_index;
  6540. }
  6541. for (int index = 0; index < AC_QUANTITY; index++)
  6542. {
  6543. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6544. {
  6545. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6546. }
  6547. }
  6548. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6549. }
  6550. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6551. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6552. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6553. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6554. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6555. }
  6556. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6557. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6558. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6559. (dataType == ReadingContext_Trigger))
  6560. {
  6561. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6562. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6563. {
  6564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6565. {
  6566. tempIndex = ((gun_index==2) ? 1: 0);
  6567. }
  6568. else
  6569. {
  6570. tempIndex = gun_index;
  6571. }
  6572. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6573. {
  6574. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6575. {
  6576. if(dataType == ReadingContext_Sample_Clock)
  6577. {
  6578. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6579. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6580. }
  6581. else if(dataType == ReadingContext_Sample_Periodic)
  6582. {
  6583. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6584. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6585. }
  6586. else
  6587. {
  6588. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6589. }
  6590. }
  6591. } // END OF FOR CHAdeMO_QUANTITY
  6592. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6593. }
  6594. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6595. {
  6596. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6597. {
  6598. tempIndex = ((gun_index==2) ? 1: 0);
  6599. }
  6600. else
  6601. {
  6602. tempIndex = gun_index;
  6603. }
  6604. for (int index = 0; index < CCS_QUANTITY; index++)
  6605. {
  6606. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6607. {
  6608. if(dataType == ReadingContext_Sample_Clock)
  6609. {
  6610. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6611. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6612. }
  6613. else if(dataType == ReadingContext_Sample_Periodic)
  6614. {
  6615. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6616. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6617. }
  6618. else
  6619. {
  6620. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6621. }
  6622. }
  6623. } // END OF CCS_QUANTITY
  6624. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6625. }
  6626. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6627. {
  6628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6629. {
  6630. tempIndex = ((gun_index==2) ? 1: 0);
  6631. }
  6632. else
  6633. {
  6634. tempIndex = gun_index;
  6635. }
  6636. for (int index = 0; index < GB_QUANTITY; index++)
  6637. {
  6638. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6639. {
  6640. if(dataType == ReadingContext_Sample_Clock)
  6641. {
  6642. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6643. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6644. }
  6645. else if(dataType == ReadingContext_Sample_Periodic)
  6646. {
  6647. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6648. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6649. }
  6650. else
  6651. {
  6652. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6653. }
  6654. }
  6655. } // END OF GB_QUANTITY
  6656. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6657. }
  6658. else if(gunType[gun_index] == GUN_TYPE_DO)
  6659. {
  6660. tempIndex = gun_index;
  6661. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6662. {
  6663. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6664. {
  6665. if(dataType == ReadingContext_Sample_Clock)
  6666. {
  6667. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  6668. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6669. }
  6670. else if(dataType == ReadingContext_Sample_Periodic)
  6671. {
  6672. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6673. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6674. }
  6675. else
  6676. {
  6677. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6678. }
  6679. }
  6680. }
  6681. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6682. }
  6683. else
  6684. {
  6685. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6686. {
  6687. tempIndex = 2;
  6688. }
  6689. else
  6690. {
  6691. tempIndex = gun_index;
  6692. }
  6693. for (int index = 0; index < AC_QUANTITY; index++)
  6694. {
  6695. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6696. {
  6697. if(dataType == ReadingContext_Sample_Clock)
  6698. {
  6699. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6700. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6701. }
  6702. else if(dataType == ReadingContext_Sample_Periodic)
  6703. {
  6704. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6705. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6706. }
  6707. else
  6708. {
  6709. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6710. }
  6711. }
  6712. }
  6713. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6714. }
  6715. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6716. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6717. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6718. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6719. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6720. }
  6721. //********************************(4)Power.Active.Import************************************************/
  6722. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6723. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6724. (dataType == ReadingContext_Trigger))
  6725. {
  6726. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6727. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6728. {
  6729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6730. {
  6731. tempIndex = ((gun_index==2) ? 1: 0);
  6732. }
  6733. else
  6734. {
  6735. tempIndex = gun_index;
  6736. }
  6737. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6738. {
  6739. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6740. {
  6741. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6742. }
  6743. } // END OF FOR
  6744. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6745. }
  6746. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6747. {
  6748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6749. {
  6750. tempIndex = ((gun_index==2) ? 1: 0);
  6751. }
  6752. else
  6753. {
  6754. tempIndex = gun_index;
  6755. }
  6756. for (int index = 0; index < CCS_QUANTITY; index++)
  6757. {
  6758. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6759. {
  6760. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6761. }
  6762. }
  6763. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6764. }
  6765. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6766. {
  6767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6768. {
  6769. tempIndex = ((gun_index==2) ? 1: 0);
  6770. }
  6771. else
  6772. {
  6773. tempIndex = gun_index;
  6774. }
  6775. for (int index = 0; index < GB_QUANTITY; index++)
  6776. {
  6777. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6778. {
  6779. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6780. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6781. }
  6782. }
  6783. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6784. }
  6785. else if(gunType[gun_index] == GUN_TYPE_DO)
  6786. {
  6787. tempIndex = gun_index;
  6788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6789. {
  6790. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6791. {
  6792. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6793. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6794. }
  6795. }
  6796. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6797. }
  6798. else
  6799. {
  6800. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6801. {
  6802. tempIndex = 2;
  6803. }
  6804. else
  6805. {
  6806. tempIndex = gun_index;
  6807. }
  6808. for (int index = 0; index < AC_QUANTITY; index++)
  6809. {
  6810. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6811. {
  6812. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6813. }
  6814. }
  6815. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6816. }
  6817. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6818. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6819. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6820. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6821. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6822. }
  6823. //***********************************************(5)VOLTAGE L1******************************************************/
  6824. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6825. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6826. (dataType == ReadingContext_Trigger))
  6827. {
  6828. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6829. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6830. {
  6831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6832. {
  6833. tempIndex = ((gun_index==2) ? 1: 0);
  6834. }
  6835. else
  6836. {
  6837. tempIndex = gun_index;
  6838. }
  6839. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6840. {
  6841. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6842. {
  6843. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6844. }
  6845. }
  6846. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6847. }
  6848. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6849. {
  6850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6851. {
  6852. tempIndex = ((gun_index==2) ? 1: 0);
  6853. }
  6854. else
  6855. {
  6856. tempIndex = gun_index;
  6857. }
  6858. for (int index = 0; index < CCS_QUANTITY; index++)
  6859. {
  6860. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6861. {
  6862. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6863. }
  6864. }
  6865. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6866. }
  6867. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6868. {
  6869. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6870. {
  6871. tempIndex = ((gun_index==2) ? 1: 0);
  6872. }
  6873. else
  6874. {
  6875. tempIndex = gun_index;
  6876. }
  6877. for (int index = 0; index < GB_QUANTITY; index++)
  6878. {
  6879. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6880. {
  6881. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6882. }
  6883. }
  6884. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6885. }
  6886. else if(gunType[gun_index] == GUN_TYPE_DO)
  6887. {
  6888. tempIndex = gun_index;
  6889. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6890. {
  6891. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6892. {
  6893. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6894. }
  6895. }
  6896. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6897. }
  6898. else
  6899. {
  6900. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6901. {
  6902. tempIndex = 2;
  6903. }
  6904. else
  6905. {
  6906. tempIndex = gun_index;
  6907. }
  6908. for (int index = 0; index < AC_QUANTITY; index++)
  6909. {
  6910. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6911. {
  6912. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6913. }
  6914. }
  6915. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6916. }
  6917. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6918. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6919. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6921. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6922. }
  6923. //***********************************************(6)SOC******************************************************/
  6924. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6925. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6926. (dataType == ReadingContext_Trigger))
  6927. {
  6928. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6929. {
  6930. //idx_sample=5;
  6931. //sampledValue = NULL;
  6932. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6933. {
  6934. tempIndex = ((gun_index==2) ? 1: 0);
  6935. }
  6936. else
  6937. {
  6938. tempIndex = gun_index;
  6939. }
  6940. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6941. {
  6942. //tempIndex = ((gun_index==2) ? 1: 0);
  6943. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6944. {
  6945. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6946. {
  6947. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6948. }
  6949. }
  6950. }
  6951. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6952. {
  6953. //tempIndex = ((gun_index==2) ? 1: 0);
  6954. for (int index = 0; index < CCS_QUANTITY; index++)
  6955. {
  6956. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6957. {
  6958. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6959. }
  6960. }
  6961. }
  6962. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6963. {
  6964. //tempIndex = ((gun_index==2) ? 1: 0);
  6965. for (int index = 0; index < GB_QUANTITY; index++)
  6966. {
  6967. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6968. {
  6969. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6970. }
  6971. }
  6972. }
  6973. else if(gunType[gun_index] == GUN_TYPE_DO)
  6974. {
  6975. //tempIndex = ((gun_index==2) ? 1: 0);
  6976. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6977. {
  6978. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6979. {
  6980. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6981. }
  6982. }
  6983. }
  6984. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6985. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6986. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6987. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6988. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6989. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6990. }
  6991. }
  6992. //********************************(7)Current.Import L2************************************************/
  6993. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6994. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6995. (dataType == ReadingContext_Trigger))
  6996. {
  6997. // Only for AC 3 phase
  6998. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6999. {
  7000. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7001. {
  7002. tempIndex = 2;
  7003. }
  7004. else
  7005. {
  7006. tempIndex = gun_index;
  7007. }
  7008. for (int index = 0; index < AC_QUANTITY; index++)
  7009. {
  7010. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7011. {
  7012. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7013. }
  7014. }
  7015. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7016. }
  7017. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7018. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7019. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7020. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7021. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7022. }
  7023. //********************************(8)Current.Import L3************************************************/
  7024. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7025. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7026. (dataType == ReadingContext_Trigger))
  7027. {
  7028. // Only for AC 3 phase
  7029. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7030. {
  7031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7032. {
  7033. tempIndex = 2;
  7034. }
  7035. else
  7036. {
  7037. tempIndex = gun_index;
  7038. }
  7039. for (int index = 0; index < AC_QUANTITY; index++)
  7040. {
  7041. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7042. {
  7043. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7044. }
  7045. }
  7046. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7047. }
  7048. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7049. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7050. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7051. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7052. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7053. }
  7054. //***********************************************(9)VOLTAGE L2******************************************************/
  7055. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7056. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7057. (dataType == ReadingContext_Trigger))
  7058. {
  7059. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7060. {
  7061. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7062. {
  7063. tempIndex = 2;
  7064. }
  7065. else
  7066. {
  7067. tempIndex = gun_index;
  7068. }
  7069. for (int index = 0; index < AC_QUANTITY; index++)
  7070. {
  7071. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7072. {
  7073. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7074. }
  7075. }
  7076. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7077. }
  7078. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7079. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7080. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7081. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7082. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7083. }
  7084. //***********************************************(10)VOLTAGE L3******************************************************/
  7085. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7086. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7087. (dataType == ReadingContext_Trigger))
  7088. {
  7089. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7090. {
  7091. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7092. {
  7093. tempIndex = 2;
  7094. }
  7095. else
  7096. {
  7097. tempIndex = gun_index;
  7098. }
  7099. for (int index = 0; index < AC_QUANTITY; index++)
  7100. {
  7101. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7102. {
  7103. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7104. }
  7105. }
  7106. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7107. }
  7108. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7109. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7110. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7111. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7112. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7113. }
  7114. //***********************************************(11)Current.Offered******************************************************/
  7115. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7116. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7117. (dataType == ReadingContext_Trigger))
  7118. {
  7119. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7120. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7121. {
  7122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7123. {
  7124. tempIndex = ((gun_index==2) ? 1: 0);
  7125. }
  7126. else
  7127. {
  7128. tempIndex = gun_index;
  7129. }
  7130. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7131. {
  7132. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7133. {
  7134. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  7135. }
  7136. } // END OF FOR CHAdeMO_QUANTITY
  7137. }
  7138. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7139. {
  7140. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7141. {
  7142. tempIndex = ((gun_index==2) ? 1: 0);
  7143. }
  7144. else
  7145. {
  7146. tempIndex = gun_index;
  7147. }
  7148. for (int index = 0; index < CCS_QUANTITY; index++)
  7149. {
  7150. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7151. {
  7152. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  7153. }
  7154. } // END OF CCS_QUANTITY
  7155. }
  7156. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7157. {
  7158. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7159. {
  7160. tempIndex = ((gun_index==2) ? 1: 0);
  7161. }
  7162. else
  7163. {
  7164. tempIndex = gun_index;
  7165. }
  7166. for (int index = 0; index < GB_QUANTITY; index++)
  7167. {
  7168. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7169. {
  7170. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  7171. }
  7172. } // END OF GB_QUANTITY
  7173. }
  7174. else if(gunType[gun_index] == GUN_TYPE_DO)
  7175. {
  7176. tempIndex = gun_index;
  7177. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7178. {
  7179. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7180. {
  7181. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  7182. }
  7183. }
  7184. }
  7185. else
  7186. {
  7187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7188. {
  7189. tempIndex = 2;
  7190. }
  7191. else
  7192. {
  7193. tempIndex = gun_index;
  7194. }
  7195. for (int index = 0; index < AC_QUANTITY; index++)
  7196. {
  7197. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7198. {
  7199. uint16_t currentOffer;
  7200. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7201. {
  7202. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7203. }
  7204. else
  7205. {
  7206. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7207. }
  7208. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7209. }
  7210. }
  7211. }
  7212. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7213. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7214. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7215. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7216. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7217. }
  7218. //***********************************************(12)Power.Offered******************************************************/
  7219. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7220. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7221. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7222. {
  7223. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7224. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7225. {
  7226. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7227. {
  7228. tempIndex = ((gun_index==2) ? 1: 0);
  7229. }
  7230. else
  7231. {
  7232. tempIndex = gun_index;
  7233. }
  7234. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7235. {
  7236. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7237. {
  7238. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7239. }
  7240. } // END OF FOR CHAdeMO_QUANTITY
  7241. }
  7242. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7243. {
  7244. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7245. {
  7246. tempIndex = ((gun_index==2) ? 1: 0);
  7247. }
  7248. else
  7249. {
  7250. tempIndex = gun_index;
  7251. }
  7252. for (int index = 0; index < CCS_QUANTITY; index++)
  7253. {
  7254. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7255. {
  7256. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7257. }
  7258. } // END OF CCS_QUANTITY
  7259. }
  7260. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7261. {
  7262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7263. {
  7264. tempIndex = ((gun_index==2) ? 1: 0);
  7265. }
  7266. else
  7267. {
  7268. tempIndex = gun_index;
  7269. }
  7270. for (int index = 0; index < GB_QUANTITY; index++)
  7271. {
  7272. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7273. {
  7274. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7275. }
  7276. } // END OF GB_QUANTITY
  7277. }
  7278. else if(gunType[gun_index] == GUN_TYPE_DO)
  7279. {
  7280. tempIndex = gun_index;
  7281. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7282. {
  7283. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7284. {
  7285. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7286. }
  7287. }
  7288. }
  7289. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7290. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7291. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7292. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7293. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7294. }
  7295. // Message create ====================================================================================================
  7296. if(TRUE)
  7297. {
  7298. json_object *MeterValueReq = json_object_new_object();
  7299. json_object *MeterValues = json_object_new_array();
  7300. json_object *sampledValues = json_object_new_array();
  7301. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7302. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7303. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7304. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7305. {
  7306. json_object *MeterValue = json_object_new_object();
  7307. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7308. {
  7309. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7310. {
  7311. json_object *sampledValue = json_object_new_object();
  7312. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7313. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7314. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7315. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7316. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7317. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7318. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7319. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7320. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7321. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7322. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7323. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7324. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7325. json_object_array_add(sampledValues, sampledValue);
  7326. }
  7327. }
  7328. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7329. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7330. json_object_array_add(MeterValues, MeterValue);
  7331. }
  7332. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7333. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7334. ,gun_index + 1
  7335. ,MESSAGE_TYPE_CALL
  7336. ,guid
  7337. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7338. json_object_put(MeterValueReq);
  7339. }
  7340. // Put request guid to hash map
  7341. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7342. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  7343. {
  7344. result = PASS;
  7345. //DEBUG_INFO("MeterValues mapitem pass\n");
  7346. }
  7347. if((dataType != ReadingContext_Trigger) &&
  7348. (dataType != ReadingContext_Sample_Clock) &&
  7349. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7350. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7351. else
  7352. {
  7353. if(FirstHeartBeat)
  7354. LWS_Send(queuedata +2);
  7355. }
  7356. return result;
  7357. }
  7358. int sendLogStatusNotificationRequest(char *status)
  7359. {
  7360. mtrace();
  7361. int result = PASS;
  7362. char message[4096]={0};
  7363. char guid[37]={0};
  7364. char tempdata[128]={0};
  7365. json_object *LogStatusNotification = json_object_new_object();
  7366. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7367. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7368. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7369. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7370. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7371. random_uuid(guid);
  7372. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7373. json_object_put(LogStatusNotification);
  7374. LWS_Send(message);
  7375. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7376. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7377. {
  7378. result = PASS;
  7379. }
  7380. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7381. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7382. return result;
  7383. }
  7384. int sendSecurityEventNotificationRequest()
  7385. {
  7386. mtrace();
  7387. int result = PASS;
  7388. char message[4096]={0};
  7389. char guid[37]={0};
  7390. char tempdata[128]={0};
  7391. json_object *SecurityEventNotification = json_object_new_object();
  7392. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7393. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7394. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7395. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7396. random_uuid(guid);
  7397. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7398. json_object_put(SecurityEventNotification);
  7399. LWS_Send(message);
  7400. sprintf(tempdata, "SecurityEventNotification,0");
  7401. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7402. {
  7403. result = PASS;
  7404. }
  7405. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7406. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7407. return result;
  7408. }
  7409. int sendSignCertificateRequest()
  7410. {
  7411. mtrace();
  7412. int result = PASS;
  7413. char message[4096]={0};
  7414. char guid[37]={0};
  7415. char tempdata[128]={0};
  7416. json_object *SignCertificate = json_object_new_object();
  7417. DEBUG_INFO("sendSignCertificateRequest...\n");
  7418. // Read csr file content
  7419. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7420. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7421. char *line = NULL;
  7422. size_t len = 0;
  7423. while(getline(&line, &len, fp) != -1)
  7424. {
  7425. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7426. {
  7427. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7428. }
  7429. }
  7430. fclose(fp);
  7431. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7432. random_uuid(guid);
  7433. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7434. json_object_put(SignCertificate);
  7435. LWS_Send(message);
  7436. sprintf(tempdata, "SignCertificate,0");
  7437. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7438. {
  7439. result = PASS;
  7440. }
  7441. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7442. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7443. return result;
  7444. }
  7445. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7446. {
  7447. mtrace();
  7448. int result = PASS;
  7449. char message[110]={0};
  7450. char guid[37]={0};
  7451. char tempdata[65]={0};
  7452. json_object *FirmwareStatusNotification = json_object_new_object();
  7453. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7454. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7455. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7456. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7457. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7458. random_uuid(guid);
  7459. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7460. json_object_put(FirmwareStatusNotification);
  7461. LWS_Send(message);
  7462. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7463. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7464. {
  7465. result = PASS;
  7466. }
  7467. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7468. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7469. return result;
  7470. }
  7471. //==========================================
  7472. // send confirm routine
  7473. //==========================================
  7474. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7475. {
  7476. mtrace();
  7477. int result = FAIL;
  7478. char message[100]={0};
  7479. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7480. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7481. LWS_Send(message);
  7482. result = TRUE;
  7483. return result;
  7484. }
  7485. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7486. {
  7487. mtrace();
  7488. int result = FAIL;
  7489. char message[100]={0};
  7490. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7491. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7492. LWS_Send(message);
  7493. result = TRUE;
  7494. return result;
  7495. }
  7496. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7497. {
  7498. mtrace();
  7499. int result = FAIL;
  7500. char message[100]={0};
  7501. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7502. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7503. LWS_Send(message);
  7504. result = TRUE;
  7505. return result;
  7506. }
  7507. int sendClearCacheConfirmation(char *uuid,char *payload)
  7508. {
  7509. mtrace();
  7510. int result = FAIL;
  7511. char message[500]={0};
  7512. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7513. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7514. LWS_Send(message);
  7515. return result;
  7516. }
  7517. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7518. {
  7519. mtrace();
  7520. int result = FAIL;
  7521. char message[500]={0};
  7522. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7523. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7524. LWS_Send(message);
  7525. return result;
  7526. }
  7527. int sendDataTransferConfirmation(char *uuid,char *payload)
  7528. {
  7529. mtrace();
  7530. char statusStr[20]={0};
  7531. char dataStr[10]={0};
  7532. char sstr[20]={0};
  7533. int c = 0;
  7534. char *loc;
  7535. int result = FAIL;
  7536. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7537. /**********************status**************************/
  7538. loc = strstr(payload, "status");
  7539. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7540. c = 0;
  7541. while (loc[3+strlen("status")+c] != '\"')
  7542. {
  7543. sstr[c] = loc[3+strlen("status")+c];
  7544. c++;
  7545. }
  7546. sstr[c] = '\0';
  7547. strcpy(statusStr, sstr);
  7548. /**********************data**************************/
  7549. loc = strstr(payload, "data");
  7550. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7551. c = 0;
  7552. while (loc[3+strlen("data")+c] != '\"')
  7553. {
  7554. sstr[c] = loc[3+strlen("data")+c];
  7555. c++;
  7556. }
  7557. sstr[c] = '\0';
  7558. strcpy(dataStr, sstr);
  7559. return result;
  7560. }
  7561. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7562. {
  7563. mtrace();
  7564. int result = FAIL;
  7565. char message[1000]={0};
  7566. int CompositeScheduleIndex = 0;
  7567. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7568. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7569. if(nPeriod == 0)
  7570. {
  7571. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7572. {
  7573. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7574. ,MESSAGE_TYPE_CALLRESULT
  7575. ,uuid
  7576. ,payload
  7577. ,connectorIdInt);
  7578. }
  7579. else
  7580. {
  7581. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7582. ,MESSAGE_TYPE_CALLRESULT
  7583. ,uuid
  7584. ,payload
  7585. ,connectorIdInt
  7586. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7587. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7588. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7589. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7590. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7591. }
  7592. }
  7593. else
  7594. {
  7595. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7596. ,MESSAGE_TYPE_CALLRESULT
  7597. ,uuid
  7598. ,payload
  7599. ,connectorIdInt
  7600. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7601. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7602. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7603. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7604. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7605. {
  7606. if (idx_sample == 0)
  7607. {
  7608. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7609. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7610. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7611. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7612. }
  7613. else
  7614. {
  7615. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7616. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7617. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7618. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7619. }
  7620. }
  7621. sprintf(message + strlen(message), "]}}]");
  7622. }
  7623. LWS_Send(message);
  7624. result = TRUE;
  7625. return result;
  7626. }
  7627. int sendGetConfigurationConfirmation(char *uuid)
  7628. {
  7629. mtrace();
  7630. int result = FAIL;
  7631. int MaxKeySupported = 0;
  7632. int sentConfigurationNumber= 0;
  7633. int sentunConfigurationNumber= 0;
  7634. char message[1024*10]={0};
  7635. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7636. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7637. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7638. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7639. ,MESSAGE_TYPE_CALLRESULT
  7640. ,uuid );
  7641. //configuration key
  7642. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7643. {
  7644. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7645. {
  7646. if (sentConfigurationNumber == 0)
  7647. {
  7648. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7649. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7650. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7651. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7652. }
  7653. else
  7654. {
  7655. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7656. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7657. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7658. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7659. }
  7660. sentConfigurationNumber = sentConfigurationNumber + 1;
  7661. }
  7662. }
  7663. sprintf(message + strlen(message), "]");
  7664. if(UnknownKeynum != 0)
  7665. {
  7666. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7667. //unkown key
  7668. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7669. {
  7670. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7671. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7672. if(sentunConfigurationNumber == 0)
  7673. {
  7674. sprintf(message + strlen(message), "\"%s\""
  7675. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7676. }
  7677. else
  7678. {
  7679. sprintf(message + strlen(message), ",\"%s\""
  7680. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7681. }
  7682. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7683. }
  7684. sprintf(message + strlen(message), "]");
  7685. }
  7686. sprintf(message + strlen(message), "}]");
  7687. LWS_Send(message);
  7688. return result;
  7689. }
  7690. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7691. {
  7692. mtrace();
  7693. int result = FAIL;
  7694. char message[400]={0};
  7695. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7696. if(strcmp(payload,"")==0)
  7697. {
  7698. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7699. }
  7700. else
  7701. {
  7702. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7703. }
  7704. LWS_Send(message);
  7705. result = TRUE;
  7706. return result;
  7707. }
  7708. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7709. {
  7710. mtrace();
  7711. int result = FAIL;
  7712. char message[80]={0};
  7713. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7714. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7715. LWS_Send(message);
  7716. result = TRUE;
  7717. return result;
  7718. }
  7719. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7720. {
  7721. mtrace();
  7722. int result = FAIL;
  7723. char message[80]={0};
  7724. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7725. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7726. LWS_Send(message);
  7727. result = TRUE;
  7728. return result;
  7729. }
  7730. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7731. {
  7732. mtrace();
  7733. int result = FAIL;
  7734. char message[80]={0};
  7735. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7736. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7737. LWS_Send(message);
  7738. result = TRUE;
  7739. return result;
  7740. }
  7741. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7742. {
  7743. mtrace();
  7744. int result = FAIL;
  7745. char message[80]={0};
  7746. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7747. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7748. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7749. LWS_Send(message);
  7750. result = TRUE;
  7751. return result;
  7752. }
  7753. int sendResetConfirmation(char *uuid,char *payload)
  7754. {
  7755. mtrace();
  7756. int result = FAIL;
  7757. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7758. char message[80]={0};
  7759. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7760. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7761. LWS_Send(message);
  7762. result = TRUE;
  7763. return result;
  7764. }
  7765. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7766. {
  7767. mtrace();
  7768. int result = FAIL;
  7769. char message[500]={0};
  7770. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7771. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7772. LWS_Send(message);
  7773. result = TRUE;
  7774. return result;
  7775. }
  7776. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7777. {
  7778. mtrace();
  7779. int result = FAIL;
  7780. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7781. char message[80]={0};
  7782. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7783. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7784. LWS_Send(message);
  7785. result = TRUE;
  7786. return result;
  7787. }
  7788. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7789. {
  7790. mtrace();
  7791. int result = FAIL;
  7792. char message[80]={0};
  7793. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7794. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7795. LWS_Send(message);
  7796. result = TRUE;
  7797. return result;
  7798. }
  7799. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7800. {
  7801. mtrace();
  7802. int result = FAIL;
  7803. char message[80]={0};
  7804. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7805. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7806. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7807. LWS_Send(message);
  7808. result = TRUE;
  7809. return result;
  7810. }
  7811. int sendUpdateFirmwareConfirmation(char *uuid)
  7812. {
  7813. mtrace();
  7814. int result = FAIL;
  7815. char message[60]={0};
  7816. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7817. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7818. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7819. LWS_Send(message);
  7820. result = TRUE;
  7821. return result;
  7822. }
  7823. int sendCertificateSignedConfirmation(char *uuid)
  7824. {
  7825. mtrace();
  7826. int result = PASS;
  7827. char message[4096]={0};
  7828. json_object *CertificateSigned = json_object_new_object();
  7829. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7830. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7831. sprintf(message,"[%d,\"%s\",%s]"
  7832. ,MESSAGE_TYPE_CALLRESULT
  7833. ,uuid
  7834. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7835. json_object_put(CertificateSigned);
  7836. LWS_Send(message);
  7837. return result;
  7838. }
  7839. int sendDeleteCertificateConfirmation(char *uuid)
  7840. {
  7841. mtrace();
  7842. int result = PASS;
  7843. char message[4096]={0};
  7844. json_object *DeleteCertificate = json_object_new_object();
  7845. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7846. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7847. sprintf(message,"[%d,\"%s\",%s]"
  7848. ,MESSAGE_TYPE_CALLRESULT
  7849. ,uuid
  7850. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7851. json_object_put(DeleteCertificate);
  7852. LWS_Send(message);
  7853. return result;
  7854. }
  7855. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7856. {
  7857. mtrace();
  7858. int result = PASS;
  7859. char message[4096]={0};
  7860. json_object *ExtendedTriggerMessage = json_object_new_object();
  7861. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7862. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7863. sprintf(message,"[%d,\"%s\",%s]"
  7864. ,MESSAGE_TYPE_CALLRESULT
  7865. ,uuid
  7866. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7867. json_object_put(ExtendedTriggerMessage);
  7868. LWS_Send(message);
  7869. return result;
  7870. }
  7871. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7872. {
  7873. mtrace();
  7874. int result = PASS;
  7875. char message[4096]={0};
  7876. json_object *GetInstalledCertificateIds = json_object_new_object();
  7877. json_object *certificateHashDataDatas = json_object_new_array();
  7878. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7879. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7880. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7881. {
  7882. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7883. {
  7884. json_object *certificateHashData = json_object_new_object();
  7885. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7886. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7887. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7888. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7889. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7890. }
  7891. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7892. }
  7893. else
  7894. {
  7895. json_object_put(certificateHashDataDatas);
  7896. }
  7897. sprintf(message,"[%d,\"%s\",%s]"
  7898. ,MESSAGE_TYPE_CALLRESULT
  7899. ,uuid
  7900. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7901. json_object_put(GetInstalledCertificateIds);
  7902. LWS_Send(message);
  7903. return result;
  7904. }
  7905. int sendGetLogConfirmation(char *uuid)
  7906. {
  7907. mtrace();
  7908. int result = PASS;
  7909. char message[4096]={0};
  7910. json_object *GetLog = json_object_new_object();
  7911. DEBUG_INFO("sendGetLogConfirmation...\n");
  7912. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7913. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7914. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7915. sprintf(message,"[%d,\"%s\",%s]"
  7916. ,MESSAGE_TYPE_CALLRESULT
  7917. ,uuid
  7918. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7919. json_object_put(GetLog);
  7920. LWS_Send(message);
  7921. return result;
  7922. }
  7923. int sendInstallCertificateConfirmation(char *uuid)
  7924. {
  7925. mtrace();
  7926. int result = PASS;
  7927. char message[4096]={0};
  7928. json_object *InstallCertificate = json_object_new_object();
  7929. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7930. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7931. sprintf(message,"[%d,\"%s\",%s]"
  7932. ,MESSAGE_TYPE_CALLRESULT
  7933. ,uuid
  7934. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7935. json_object_put(InstallCertificate);
  7936. LWS_Send(message);
  7937. return result;
  7938. }
  7939. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7940. {
  7941. mtrace();
  7942. int result = PASS;
  7943. char message[4096]={0};
  7944. json_object *SignedUpdateFirmware = json_object_new_object();
  7945. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7946. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7947. sprintf(message,"[%d,\"%s\",%s]"
  7948. ,MESSAGE_TYPE_CALLRESULT
  7949. ,uuid
  7950. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7951. json_object_put(SignedUpdateFirmware);
  7952. LWS_Send(message);
  7953. return result;
  7954. }
  7955. int sendUnknownConfirmation(char *uuid)
  7956. {
  7957. mtrace();
  7958. int result = PASS;
  7959. char message[256]={0};
  7960. DEBUG_INFO("sendUnknownConfirmation...\n");
  7961. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7962. LWS_Send(message);
  7963. return result;
  7964. }
  7965. //==========================================
  7966. // Handle server request routine Start
  7967. //==========================================
  7968. int handleCancelReservationRequest(char *uuid, char *payload)
  7969. {
  7970. mtrace();
  7971. int result = FAIL;
  7972. int gunNO = 0;
  7973. int reservationIdInt = -1;
  7974. char comfirmstr[20];
  7975. DEBUG_INFO("handleCancelReservationRequest...\n");
  7976. json_object *CancelReservation;
  7977. CancelReservation = json_tokener_parse(payload);
  7978. if(!is_error(CancelReservation))
  7979. {
  7980. // Required data
  7981. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7982. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7983. }
  7984. json_object_put(CancelReservation);
  7985. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7986. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7987. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7988. if(reservationIdInt != -1)
  7989. {
  7990. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7991. //check Transaction active
  7992. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7993. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7994. {
  7995. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7996. {
  7997. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7998. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7999. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8000. {
  8001. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8002. }
  8003. else
  8004. {
  8005. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8006. }
  8007. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8008. goto end;
  8009. }
  8010. }
  8011. for (int index = 0; index < CCS_QUANTITY; index++)
  8012. {
  8013. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8014. {
  8015. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8016. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8017. if(gunType[2] == GUN_TYPE_CCS)
  8018. {
  8019. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8020. }
  8021. else
  8022. {
  8023. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8024. }
  8025. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8026. goto end;
  8027. }
  8028. }
  8029. for (int index = 0; index < GB_QUANTITY; index++)
  8030. {
  8031. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8032. {
  8033. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8034. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8035. if(gunType[2] == GUN_TYPE_GBT)
  8036. {
  8037. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8038. }
  8039. else
  8040. {
  8041. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8042. }
  8043. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8044. goto end;
  8045. }
  8046. }
  8047. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8048. {
  8049. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8050. {
  8051. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8052. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8053. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8054. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8055. goto end;
  8056. }
  8057. }
  8058. for (int index = 0; index < AC_QUANTITY; index++)
  8059. {
  8060. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8061. {
  8062. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8063. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8065. {
  8066. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8067. }
  8068. else
  8069. {
  8070. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8071. }
  8072. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8073. goto end;
  8074. }
  8075. }
  8076. }
  8077. //The reservationId does NOT match the reservationId
  8078. sendCancelReservationConfirmation(uuid, comfirmstr);
  8079. end:
  8080. // Fill in ocpp packet uuid
  8081. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  8082. return result;
  8083. }
  8084. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8085. {
  8086. mtrace();
  8087. int result = FAIL;
  8088. int gunIndex = -1;
  8089. char typeStr[16]={0};
  8090. char comfirmstr[20];
  8091. int specificId = FALSE;
  8092. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8093. json_object *ChangeAvailability;
  8094. ChangeAvailability = json_tokener_parse(payload);
  8095. if(!is_error(ChangeAvailability))
  8096. {
  8097. // Required data
  8098. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8099. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8100. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8101. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8102. }
  8103. json_object_put(ChangeAvailability);
  8104. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8105. {
  8106. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8107. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8108. }
  8109. else if(gunIndex == 0)
  8110. {
  8111. for(int i=0; i < gunTotalNumber; i++)
  8112. {
  8113. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  8114. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  8115. }
  8116. }
  8117. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8118. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8119. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8120. {
  8121. specificId = TRUE;
  8122. }
  8123. if(specificId == FALSE)
  8124. goto end;
  8125. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8126. {
  8127. //----------------------gunIndex is 0 ------------------------------------------------//
  8128. if(gunIndex == 0)
  8129. {
  8130. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8131. {
  8132. for(int i=0; i < gunTotalNumber; i++)
  8133. {
  8134. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8135. {
  8136. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8137. {
  8138. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8139. {
  8140. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8141. goto end;
  8142. }
  8143. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8144. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8145. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8146. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8147. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8148. {
  8149. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8150. goto end;
  8151. }
  8152. }
  8153. }//END FOR CHAdeMO_QUANTITY
  8154. for (int index = 0; index < CCS_QUANTITY; index++)
  8155. {
  8156. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8157. {
  8158. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8159. {
  8160. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8161. goto end;
  8162. }
  8163. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8164. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8165. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8166. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8167. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8168. {
  8169. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8170. goto end;
  8171. }
  8172. }
  8173. }//END FOR CCS_QUANTITY
  8174. for (int index = 0; index < GB_QUANTITY; index++)
  8175. {
  8176. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8177. {
  8178. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8179. {
  8180. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8181. goto end;
  8182. }
  8183. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8184. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8185. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8186. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8187. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8188. {
  8189. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8190. goto end;
  8191. }
  8192. }
  8193. }// END FOR GB_QUANTITY
  8194. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8195. {
  8196. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8197. {
  8198. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8199. {
  8200. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8201. goto end;
  8202. }
  8203. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8204. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8205. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8206. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8207. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8208. {
  8209. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8210. goto end;
  8211. }
  8212. }
  8213. }// END FOR GENERAL_GUN_QUANTITY
  8214. for (int index = 0; index < AC_QUANTITY; index++)
  8215. {
  8216. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8217. {
  8218. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8219. {
  8220. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8221. goto end;
  8222. }
  8223. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8224. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8225. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8226. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8227. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8228. {
  8229. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8230. goto end;
  8231. }
  8232. }
  8233. }//END FOR AC_QUANTITY
  8234. }// END FOR gunTotalNumber
  8235. }
  8236. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8237. {
  8238. for(int i=0; i < gunTotalNumber; i++)
  8239. {
  8240. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8241. {
  8242. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8243. goto end;
  8244. }
  8245. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8246. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8247. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8248. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8249. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8250. {
  8251. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8252. goto end;
  8253. }
  8254. }
  8255. }
  8256. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8257. goto end;
  8258. }
  8259. //----------------------gunIndex is not 0 ------------------------------------------------//
  8260. //check Transaction active
  8261. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8262. {
  8263. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8264. {
  8265. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8266. {
  8267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8268. goto end;
  8269. }
  8270. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8271. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8272. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8273. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8274. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8275. {
  8276. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8277. goto end;
  8278. }
  8279. else
  8280. {
  8281. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8282. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8283. goto end;
  8284. }
  8285. }
  8286. }//END FOR CHAdeMO_QUANTITY
  8287. for (int index = 0; index < CCS_QUANTITY; index++)
  8288. {
  8289. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8290. {
  8291. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8292. {
  8293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8294. goto end;
  8295. }
  8296. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8297. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8298. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8299. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8300. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8301. {
  8302. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8303. goto end;
  8304. }
  8305. else
  8306. {
  8307. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8308. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8309. goto end;
  8310. }
  8311. }
  8312. }//END FOR CCS_QUANTITY
  8313. for (int index = 0; index < GB_QUANTITY; index++)
  8314. {
  8315. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8316. {
  8317. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8318. {
  8319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8320. goto end;
  8321. }
  8322. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8323. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8324. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8325. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8326. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8327. {
  8328. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8329. goto end;
  8330. }
  8331. else
  8332. {
  8333. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8334. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8335. goto end;
  8336. }
  8337. }
  8338. }// END FOR GB_QUANTITY
  8339. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8340. {
  8341. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8342. {
  8343. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8344. {
  8345. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8346. goto end;
  8347. }
  8348. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8349. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8350. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8351. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8352. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8353. {
  8354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8355. goto end;
  8356. }
  8357. else
  8358. {
  8359. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8360. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8361. goto end;
  8362. }
  8363. }
  8364. }// END FOR GENERAL_GUN_QUANTITY
  8365. for (int index = 0; index < AC_QUANTITY; index++)
  8366. {
  8367. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8368. {
  8369. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8370. {
  8371. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8372. goto end;
  8373. }
  8374. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8375. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8376. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8377. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8378. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8379. {
  8380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8381. goto end;
  8382. }
  8383. else
  8384. {
  8385. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8387. goto end;
  8388. }
  8389. }
  8390. }//END FOR AC_QUANTITY
  8391. }//END FOR AvailabilityTypeStr[Inoperative]
  8392. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8393. {
  8394. //----------------------gunIndex is 0 ------------------------------------------------//
  8395. if(gunIndex == 0)
  8396. {
  8397. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8398. {
  8399. for(int i=0; i < gunTotalNumber; i++)
  8400. {
  8401. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8402. {
  8403. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8404. {
  8405. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8406. goto end;
  8407. }
  8408. }//END FOR CHAdeMO_QUANTITY
  8409. for (int index = 0; index < CCS_QUANTITY; index++)
  8410. {
  8411. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8412. {
  8413. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8414. goto end;
  8415. }
  8416. }//END FOR CCS_QUANTITY
  8417. for (int index = 0; index < GB_QUANTITY; index++)
  8418. {
  8419. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8420. {
  8421. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8423. goto end;
  8424. }
  8425. }// END FOR GB_QUANTITY
  8426. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8427. {
  8428. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8429. {
  8430. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8432. goto end;
  8433. }
  8434. }// END FOR GENERAL_GUN_QUANTITY
  8435. for (int index = 0; index < AC_QUANTITY; index++)
  8436. {
  8437. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8438. {
  8439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8440. goto end;
  8441. }
  8442. }//END FOR CHAdeMO_QUANTITY
  8443. }// END FOR gunTotalNumber
  8444. }
  8445. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8446. {
  8447. for(int i=0; i < gunTotalNumber; i++)
  8448. {
  8449. for (int index = 0; index < AC_QUANTITY; index++)
  8450. {
  8451. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8452. {
  8453. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8454. goto end;
  8455. }
  8456. }//END FOR CHAdeMO_QUANTITY
  8457. } // END FOR gunTotalNumber
  8458. }
  8459. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8460. goto end;
  8461. }
  8462. //----------------------gunIndex is not 0 ------------------------------------------------//
  8463. //check Transaction active
  8464. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8465. {
  8466. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8467. {
  8468. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8469. goto end;
  8470. }
  8471. }//END FOR CHAdeMO_QUANTITY
  8472. for (int index = 0; index < CCS_QUANTITY; index++)
  8473. {
  8474. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8475. {
  8476. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8477. goto end;
  8478. }
  8479. }//END FOR CCS_QUANTITY
  8480. for (int index = 0; index < GB_QUANTITY; index++)
  8481. {
  8482. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8483. {
  8484. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8485. goto end;
  8486. }
  8487. }// END FOR GB_QUANTITY
  8488. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8489. {
  8490. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8491. {
  8492. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8493. goto end;
  8494. }
  8495. }// END FOR GENERAL_GUN_QUANTITY
  8496. for (int index = 0; index < AC_QUANTITY; index++)
  8497. {
  8498. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8499. {
  8500. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8501. goto end;
  8502. }
  8503. }//END FOR AC_QUANTITY
  8504. }//END FOR AvailabilityTypeStr[Operative]
  8505. end:
  8506. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8507. {
  8508. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8509. }
  8510. else
  8511. {
  8512. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8513. }
  8514. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8515. {
  8516. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8517. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8518. }
  8519. else if(gunIndex == 0)
  8520. {
  8521. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8522. {
  8523. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8524. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8525. }
  8526. }
  8527. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8528. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8529. return result;
  8530. }
  8531. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8532. {
  8533. mtrace();
  8534. int valueInvalid = NO;
  8535. int result = FAIL;
  8536. char keystr[40]={0};
  8537. char valuestr[501]={0}; //value should be limited in 500 bytes
  8538. char comfirmstr[20]={0};
  8539. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8540. json_object *ChangeConfiguration;
  8541. ChangeConfiguration = json_tokener_parse(payload);
  8542. if(!is_error(ChangeConfiguration))
  8543. {
  8544. // Required data
  8545. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8546. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8547. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8548. {
  8549. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8550. }
  8551. else
  8552. {
  8553. valueInvalid = YES;
  8554. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8555. }
  8556. }
  8557. json_object_put(ChangeConfiguration);
  8558. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8559. {
  8560. DEBUG_ERROR("Payload is null or not accepted.\n");
  8561. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8562. }
  8563. else
  8564. {
  8565. int status = setKeyValue(keystr, valuestr);
  8566. switch(status)
  8567. {
  8568. case ConfigurationStatus_Accepted:
  8569. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8570. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8571. StoreConfigurationTable();
  8572. break;
  8573. case RebootRequired:
  8574. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8575. StoreConfigurationTable();
  8576. break;
  8577. case NotSupported:
  8578. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8579. break;
  8580. case ConfigurationStatus_Rejected:
  8581. default:
  8582. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8583. break;
  8584. }
  8585. }
  8586. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8587. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8588. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8589. {
  8590. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8591. SetOcppConnStatus(FALSE);
  8592. }
  8593. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8594. {
  8595. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8596. }
  8597. return result;
  8598. }
  8599. int handleClearCacheRequest(char *uuid, char *payload)
  8600. {
  8601. mtrace();
  8602. int result = FAIL;
  8603. char comfirmstr[20];
  8604. char rmFileCmd[100]={0};
  8605. struct stat stats;
  8606. DEBUG_INFO("handleClearCacheRequest...\n");
  8607. stat("/Storage/OCPP_PH", &stats);
  8608. // Check for directory existence
  8609. if (S_ISDIR(stats.st_mode) == 1)
  8610. {}
  8611. else
  8612. {
  8613. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8614. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8615. system(rmFileCmd);
  8616. }
  8617. if(OCPP_cleanLocalCache())
  8618. {
  8619. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8620. }
  8621. else
  8622. {
  8623. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8624. }
  8625. sendClearCacheConfirmation(uuid, comfirmstr);
  8626. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8627. return result;
  8628. }
  8629. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8630. {
  8631. mtrace();
  8632. int result = FAIL;
  8633. int resultRename;
  8634. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8635. char chargingProfilePurposeStr[26]={0};
  8636. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8637. char tempchargingProfilePurposeStr[26]={0};
  8638. char str[100]={0};
  8639. char fname[200]={0};
  8640. char comfirmstr[20]={0};
  8641. char word[1600]={0};
  8642. int clearflag = FALSE;
  8643. int chargingProfileIdIsNULL = FALSE;
  8644. int connectorIsNULL = FALSE;
  8645. int chargingProfilePurposeIsNULL = FALSE;
  8646. int stackLevelIsNULL = FALSE;
  8647. //int GotoEnd = FALSE;
  8648. FILE *fptr1, *fptr2;
  8649. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8650. int n_chargingProfile=0;
  8651. int isEmptyFile = FALSE;
  8652. char sLineWord[1600]={0};
  8653. char chargingProfiles[10][100]={0};
  8654. int ChargeProfileCount = 0;
  8655. int ch;
  8656. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8657. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8658. json_object *ClearChargingProfile;
  8659. ClearChargingProfile = json_tokener_parse(payload);
  8660. if(!is_error(ClearChargingProfile))
  8661. {
  8662. // Optional data
  8663. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8664. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8665. else
  8666. chargingProfileIdIsNULL = TRUE;
  8667. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8668. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8669. else
  8670. connectorIsNULL = TRUE;
  8671. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8672. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8673. else
  8674. chargingProfilePurposeIsNULL = TRUE;
  8675. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8676. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8677. else
  8678. stackLevelIsNULL = TRUE;
  8679. }
  8680. json_object_put(ClearChargingProfile);
  8681. if(connectorIsNULL == FALSE)
  8682. {
  8683. switch(connectorIdInt)
  8684. {
  8685. case 0:
  8686. if(chargingProfilePurposeIsNULL == TRUE)
  8687. {
  8688. int l = 0;
  8689. strcpy(fname, ChargePointMaxProfile_JSON);
  8690. if((access(fname,F_OK))!=-1)
  8691. {
  8692. strcpy(chargingProfiles[l], fname);
  8693. l = l + 1;
  8694. }
  8695. strcpy(fname, TxDefaultProfile_0_JSON);
  8696. if((access(fname,F_OK))!=-1)
  8697. {
  8698. strcpy(chargingProfiles[l], fname);
  8699. l = l + 1;
  8700. }
  8701. ChargeProfileCount = l;
  8702. }
  8703. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8704. {
  8705. strcpy(fname, ChargePointMaxProfile_JSON);
  8706. if((access(fname,F_OK))!=-1)
  8707. {
  8708. strcpy(chargingProfiles[0], fname);
  8709. ChargeProfileCount = 1;
  8710. }
  8711. }
  8712. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8713. {
  8714. strcpy(fname, TxDefaultProfile_0_JSON);
  8715. if((access(fname,F_OK))!=-1)
  8716. {
  8717. strcpy(chargingProfiles[0], fname);
  8718. ChargeProfileCount = 1;
  8719. }
  8720. }
  8721. break;
  8722. default:
  8723. if(chargingProfilePurposeIsNULL == TRUE)
  8724. {
  8725. int m = 0;
  8726. memset(fname, 0, ARRAY_SIZE(fname));
  8727. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8728. if((access(fname,F_OK))!=-1)
  8729. {
  8730. strcpy(chargingProfiles[m], fname);
  8731. m = m + 1;
  8732. }
  8733. memset(fname, 0, ARRAY_SIZE(fname));
  8734. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8735. if((access(fname,F_OK))!=-1)
  8736. {
  8737. strcpy(chargingProfiles[m], fname);
  8738. m = m + 1;
  8739. }
  8740. ChargeProfileCount = m;
  8741. }
  8742. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8743. {
  8744. //strcpy(fname, TxDefaultProfile_1_JSON);
  8745. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8746. if((access(fname,F_OK))!=-1)
  8747. {
  8748. strcpy(chargingProfiles[0], fname);
  8749. ChargeProfileCount = 1;
  8750. }
  8751. }
  8752. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8753. {
  8754. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8755. if((access(fname,F_OK))!=-1)
  8756. {
  8757. strcpy(chargingProfiles[0], fname);
  8758. ChargeProfileCount = 1;
  8759. }
  8760. //strcpy(fname, TxProfile_1_JSON);
  8761. }
  8762. //strcpy(fname, ChargePointMaxProfile_JSON );
  8763. break;
  8764. }
  8765. }
  8766. else // Check all Charging Profiles
  8767. {
  8768. int i = 0;
  8769. char fnametemp[200]={0};
  8770. ChargeProfileCount = 0;
  8771. //Check ChargePointMaxProfile.json exit
  8772. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8773. {
  8774. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8775. i = i + 1;
  8776. }
  8777. //Check TxDefaultProfile_0.json exit
  8778. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8779. {
  8780. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8781. i = i + 1;
  8782. }
  8783. //Check TxDefaultProfile_%d.json
  8784. for(int j=1; j <= gunTotalNumber; j++)
  8785. {
  8786. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8787. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8788. if((access(fnametemp,F_OK))!=-1)
  8789. {
  8790. strcpy(chargingProfiles[i], fnametemp);
  8791. i = i + 1;
  8792. }
  8793. }
  8794. //Check TxProfile_%d.json
  8795. for(int j=1; j <= gunTotalNumber; j++)
  8796. {
  8797. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8798. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8799. if((access(fnametemp,F_OK))!=-1)
  8800. {
  8801. strcpy(chargingProfiles[i], fnametemp);
  8802. i = i + 1;
  8803. }
  8804. }
  8805. ChargeProfileCount = i;
  8806. }// End connectorIsNULL is TRUE
  8807. if(ChargeProfileCount == 0)
  8808. {
  8809. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8810. goto end;
  8811. }
  8812. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8813. {
  8814. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8815. goto end;
  8816. }
  8817. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8818. {
  8819. memset(str, 0, ARRAY_SIZE(str));
  8820. // clear temp file
  8821. sprintf(str,"rm -f %s",temp);
  8822. system(str);
  8823. for(int k=0; k < ChargeProfileCount; k++)
  8824. {
  8825. memset(str, 0, ARRAY_SIZE(str));
  8826. //clear file in C
  8827. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8828. system(str);
  8829. }
  8830. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8831. goto end;
  8832. }
  8833. else if(connectorIsNULL == TRUE)
  8834. {
  8835. for(int k=0; k < ChargeProfileCount; k++)
  8836. {
  8837. fptr1 = fopen(chargingProfiles[k], "r");
  8838. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8839. //Check Charging Profile Count
  8840. while(fscanf(fptr1, "%s", word) != EOF)
  8841. {
  8842. //DEBUG_INFO("word=%s\n",word);
  8843. if(strstr(word, "chargingProfileId")!= NULL)
  8844. {
  8845. //DEBUG_INFO("test chargingProfileId \n");
  8846. n_chargingProfile = n_chargingProfile + 1;
  8847. //DEBUG_INFO("chargingProfileId Found\n");
  8848. }
  8849. }
  8850. rewind(fptr1);
  8851. //search Charging Profile Element
  8852. //int i= 0;
  8853. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8854. {
  8855. json_object *tmpProfilee;
  8856. tmpProfilee = json_tokener_parse(sLineWord);
  8857. if(!is_error(tmpProfilee))
  8858. {
  8859. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8860. {
  8861. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8862. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8863. }
  8864. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8865. {
  8866. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8867. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8868. }
  8869. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8870. {
  8871. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8872. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8873. }
  8874. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8875. {
  8876. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8877. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8878. }
  8879. }
  8880. json_object_put(tmpProfilee);
  8881. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8882. {
  8883. //------- not write to fptr2-------//
  8884. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8885. //clearflag = TRUE;
  8886. }
  8887. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8888. {
  8889. //------- not write to fptr2-------//
  8890. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8891. }
  8892. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8893. {
  8894. //------- not write to fptr2-------//
  8895. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8896. }
  8897. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8898. {
  8899. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8900. }
  8901. else
  8902. {
  8903. fprintf(fptr2, sLineWord);//writing data into file
  8904. }
  8905. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8906. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8907. if(clearflag == TRUE)
  8908. {
  8909. fclose(fptr1);
  8910. fclose(fptr2);
  8911. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8912. system(str);
  8913. // clear temp file
  8914. sprintf(str,"rm -f %s",temp);
  8915. system(str);
  8916. }
  8917. else
  8918. {
  8919. fclose(fptr1);
  8920. fclose(fptr2);
  8921. memset(str, 0, ARRAY_SIZE(str));
  8922. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8923. system(str);
  8924. resultRename = rename(temp, chargingProfiles[k]);
  8925. if(resultRename == 0)
  8926. {
  8927. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8928. }
  8929. else
  8930. {
  8931. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8932. }
  8933. if(comfirmstr[0]== 0)
  8934. {
  8935. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8936. }
  8937. //Check chargingProfile is empty file
  8938. /*------ Read the file ----------------*/
  8939. fptr1=fopen(chargingProfiles[k],"r");
  8940. ch=fgetc(fptr1);
  8941. rewind(fptr1);
  8942. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8943. if(ch!=EOF)
  8944. {
  8945. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8946. {
  8947. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8948. if(sLineWord[0]=='\0')
  8949. {
  8950. isEmptyFile = TRUE;
  8951. break;
  8952. }
  8953. else
  8954. {
  8955. isEmptyFile = FALSE;
  8956. break;
  8957. }
  8958. }
  8959. }
  8960. else
  8961. isEmptyFile = TRUE;
  8962. fclose(fptr1);
  8963. if(isEmptyFile == TRUE)
  8964. {
  8965. memset(str, 0, ARRAY_SIZE(str));
  8966. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8967. system(str);
  8968. }
  8969. }
  8970. }// End of while(int k=0; k < ChargePointCount; k++)
  8971. }
  8972. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8973. {
  8974. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8975. for(int k=0; k < ChargeProfileCount; k++)
  8976. {
  8977. fptr1 = fopen(chargingProfiles[k], "r");
  8978. fptr2 = fopen(temp, "w+");
  8979. //Check Charging Profile Count
  8980. while(fscanf(fptr1, "%s", word) != EOF)
  8981. {
  8982. //DEBUG_INFO("word=%s\n",word);
  8983. if(strstr(word, "chargingProfileId")!= NULL)
  8984. {
  8985. n_chargingProfile = n_chargingProfile + 1;
  8986. }
  8987. }
  8988. rewind(fptr1);
  8989. //search Charging Profile Element
  8990. //int i= 0;
  8991. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8992. {
  8993. json_object *tmpProfilee;
  8994. tmpProfilee = json_tokener_parse(sLineWord);
  8995. if(!is_error(tmpProfilee))
  8996. {
  8997. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8998. {
  8999. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9000. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9001. }
  9002. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9003. {
  9004. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9005. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9006. }
  9007. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9008. {
  9009. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9010. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9011. }
  9012. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9013. {
  9014. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9015. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9016. }
  9017. }
  9018. json_object_put(tmpProfilee);
  9019. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9020. {
  9021. //------- not write to fptr2-------//
  9022. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9023. //clearflag = TRUE;
  9024. }
  9025. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9026. {
  9027. //------- not write to fptr2-------//
  9028. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9029. }
  9030. else if(stackLevelIsNULL == TRUE)
  9031. {
  9032. //Clear Whole File
  9033. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9034. clearflag = TRUE;
  9035. break;
  9036. }
  9037. else
  9038. {
  9039. fprintf(fptr2, sLineWord);//writing data into file
  9040. }
  9041. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9042. }
  9043. if(clearflag == TRUE)
  9044. {
  9045. fclose(fptr1);
  9046. fclose(fptr2);
  9047. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9048. system(str);
  9049. // clear temp file
  9050. sprintf(str,"rm -f %s",temp);
  9051. system(str);
  9052. }
  9053. else
  9054. {
  9055. fclose(fptr1);
  9056. fclose(fptr2);
  9057. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9058. system(str);
  9059. resultRename = rename(temp, chargingProfiles[k]);
  9060. if(resultRename == 0)
  9061. {
  9062. DEBUG_INFO("File ChargingProfile renamed successfully");
  9063. }
  9064. else
  9065. {
  9066. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9067. }
  9068. if(comfirmstr[0]== 0)
  9069. {
  9070. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9071. }
  9072. //Check chargingProfile is empty file
  9073. /*------ Read the file ----------------*/
  9074. fptr1=fopen(chargingProfiles[k],"r");
  9075. ch=fgetc(fptr1);
  9076. rewind(fptr1);
  9077. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9078. if(ch!=EOF)
  9079. {
  9080. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9081. {
  9082. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9083. if(sLineWord[0]=='\0')
  9084. {
  9085. isEmptyFile = TRUE;
  9086. break;
  9087. }
  9088. else
  9089. {
  9090. isEmptyFile = FALSE;
  9091. break;
  9092. }
  9093. }
  9094. }
  9095. else
  9096. isEmptyFile = TRUE;
  9097. fclose(fptr1);
  9098. if(isEmptyFile == TRUE)
  9099. {
  9100. memset(str, 0, ARRAY_SIZE(str));
  9101. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9102. system(str);
  9103. }
  9104. /*------- End of reading ---------------*/
  9105. }
  9106. } // while(int k=0; k < ChargeProfileCount; k++)
  9107. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9108. end:
  9109. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9110. {
  9111. if(connectorIdInt == 0)
  9112. {
  9113. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9114. {
  9115. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  9116. }
  9117. }
  9118. else
  9119. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  9120. }
  9121. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9122. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9123. return result;
  9124. }
  9125. void createFirmwareVersionByDataTransfer(void)
  9126. {
  9127. json_object *FirmwareDataTransfer = json_object_new_object();
  9128. // AC & DC model
  9129. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9130. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9131. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9132. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9133. // DC model
  9134. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9135. {
  9136. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9137. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9138. (gunType[3] != GUN_TYPE_UNKNOWN))
  9139. {
  9140. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9141. }
  9142. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9143. {
  9144. // DS DM DW
  9145. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9146. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9147. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9148. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9149. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9150. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9151. }
  9152. else
  9153. {
  9154. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9155. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9156. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9157. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9158. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9159. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9160. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9161. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9162. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9163. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9164. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9165. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9166. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9167. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9168. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9169. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9170. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9171. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9172. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9173. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9174. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9175. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9176. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9177. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9178. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9179. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9180. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9181. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9182. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9183. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9184. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9185. }
  9186. }
  9187. // 4G model
  9188. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9189. {
  9190. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9191. }
  9192. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9193. json_object_put(FirmwareDataTransfer);
  9194. }
  9195. int handleDataTransferRequest(char *uuid, char *payload)
  9196. {
  9197. mtrace();
  9198. json_object *response = json_object_new_object();
  9199. int result = FAIL;
  9200. char tempvendorId[255]={0};
  9201. char tempmessageId[50]={0};
  9202. char tempdata[1024]={0};
  9203. char message[2048]={0};
  9204. DEBUG_INFO("handleDataTransferRequest...\n");
  9205. if((uuid != NULL) && (payload != NULL))
  9206. {
  9207. json_object *DataTransfer;
  9208. DataTransfer = json_tokener_parse(payload);
  9209. if(!is_error(DataTransfer))
  9210. {
  9211. // Required data
  9212. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9213. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9214. // Optional data
  9215. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9216. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9217. if(json_object_object_get(DataTransfer, "data") != NULL)
  9218. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9219. result = PASS;
  9220. }
  9221. json_object_put(DataTransfer);
  9222. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9223. {
  9224. // Send all moudle firmware version on EVSE
  9225. createFirmwareVersionByDataTransfer();
  9226. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9227. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9228. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9229. json_object_put(response);
  9230. }
  9231. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9232. {
  9233. system("/usr/bin/run_tmate_restart.sh &");
  9234. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9235. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9236. json_object_put(response);
  9237. }
  9238. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9239. {
  9240. json_object *data;
  9241. data = json_tokener_parse(tempdata);
  9242. if(!is_error(data))
  9243. {
  9244. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9245. {
  9246. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9247. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9248. if(json_object_object_get(data, "SOC") != NULL)
  9249. {
  9250. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9251. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9252. }
  9253. if(json_object_object_get(data, "Energy") != NULL)
  9254. {
  9255. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9256. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9257. }
  9258. if(json_object_object_get(data, "Duration") != NULL)
  9259. {
  9260. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9261. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9262. }
  9263. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9264. }
  9265. else
  9266. {
  9267. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9268. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9269. }
  9270. }
  9271. else
  9272. {
  9273. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9274. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9275. }
  9276. json_object_put(data);
  9277. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9278. json_object_put(response);
  9279. }
  9280. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9281. {
  9282. json_object *data;
  9283. data = json_tokener_parse(tempdata);
  9284. if(!is_error(data))
  9285. {
  9286. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9287. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9288. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9289. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9290. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9291. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9292. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9293. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9294. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9295. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9296. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9297. }
  9298. else
  9299. {
  9300. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9301. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9302. }
  9303. json_object_put(data);
  9304. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9305. json_object_put(response);
  9306. }
  9307. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9308. {
  9309. json_object *data;
  9310. data = json_tokener_parse(tempdata);
  9311. if(!is_error(data))
  9312. {
  9313. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9314. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9315. if(json_object_object_get(data, "idToken") != NULL)
  9316. {
  9317. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9318. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9319. }
  9320. else
  9321. {
  9322. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9323. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9324. }
  9325. if(json_object_object_get(data, "price") != NULL) //v1.0
  9326. {
  9327. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9328. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9329. }
  9330. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9331. {
  9332. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9333. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9334. }
  9335. else
  9336. {
  9337. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9338. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9339. }
  9340. }
  9341. else
  9342. {
  9343. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9344. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9345. }
  9346. json_object_put(data);
  9347. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9348. json_object_put(response);
  9349. }
  9350. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9351. {
  9352. json_object *data;
  9353. data = json_tokener_parse(tempdata);
  9354. if(!is_error(data))
  9355. {
  9356. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9357. if(json_object_object_get(data, "txId") != NULL)
  9358. {
  9359. // California pricing V1.0
  9360. DEBUG_INFO("California pricing V1.0\n");
  9361. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9362. sprintf((char*)dmsVersion, "1.0");
  9363. for(int idx = 0;idx<gunTotalNumber;idx++)
  9364. {
  9365. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9366. {
  9367. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9368. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9369. if(json_object_object_get(data, "description") != NULL)
  9370. {
  9371. // California pricing V1.0
  9372. DEBUG_INFO("California pricing V1.0\n");
  9373. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9374. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9375. }
  9376. }
  9377. }
  9378. }
  9379. else if(json_object_object_get(data, "transactionId") != NULL)
  9380. {
  9381. // California pricing V2.0
  9382. DEBUG_INFO("California pricing V2.0\n");
  9383. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9384. sprintf((char*)dmsVersion, "2.0");
  9385. for(int idx=0;idx<gunTotalNumber;idx++)
  9386. {
  9387. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9388. {
  9389. if(json_object_object_get(data, "timestamp") != NULL)
  9390. {
  9391. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9392. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9393. }
  9394. else
  9395. {
  9396. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9397. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9398. }
  9399. if(json_object_object_get(data, "meterValue") != NULL)
  9400. {
  9401. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9402. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9403. }
  9404. else
  9405. {
  9406. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9407. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9408. }
  9409. if(json_object_object_get(data, "cost") != NULL)
  9410. {
  9411. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9412. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9413. }
  9414. else
  9415. {
  9416. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9417. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9418. }
  9419. if(json_object_object_get(data, "state") != NULL)
  9420. {
  9421. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9422. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9423. }
  9424. else
  9425. {
  9426. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9427. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9428. }
  9429. if(json_object_object_get(data, "chargingPrice") != NULL)
  9430. {
  9431. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9432. {
  9433. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9434. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9435. }
  9436. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9437. {
  9438. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9439. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9440. }
  9441. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9442. {
  9443. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9444. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9445. }
  9446. }
  9447. else
  9448. {
  9449. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9450. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9451. }
  9452. if(json_object_object_get(data, "idlePrice") != NULL)
  9453. {
  9454. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9455. {
  9456. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9457. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9458. }
  9459. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9460. {
  9461. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9462. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9463. }
  9464. }
  9465. if(json_object_object_get(data, "nextPeriod") != NULL)
  9466. {
  9467. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9468. {
  9469. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9470. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9471. }
  9472. else
  9473. {
  9474. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9475. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9476. }
  9477. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9478. {
  9479. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9480. {
  9481. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  9482. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  9483. }
  9484. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9485. {
  9486. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  9487. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  9488. }
  9489. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9490. {
  9491. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  9492. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  9493. }
  9494. }
  9495. else
  9496. {
  9497. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9498. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9499. }
  9500. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9501. {
  9502. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9503. {
  9504. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  9505. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  9506. }
  9507. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9508. {
  9509. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  9510. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  9511. }
  9512. }
  9513. }
  9514. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9515. {
  9516. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9517. {
  9518. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9519. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9520. }
  9521. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9522. {
  9523. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9524. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9525. }
  9526. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9527. {
  9528. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9529. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9530. }
  9531. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  9532. {
  9533. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9534. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9535. }
  9536. }
  9537. }
  9538. }
  9539. }
  9540. else
  9541. {
  9542. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9543. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9544. }
  9545. }
  9546. else
  9547. {
  9548. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9549. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9550. }
  9551. json_object_put(data);
  9552. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9553. json_object_put(response);
  9554. }
  9555. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9556. {
  9557. json_object *data;
  9558. data = json_tokener_parse(tempdata);
  9559. if(!is_error(data))
  9560. {
  9561. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9562. if(json_object_object_get(data, "txId") != NULL)
  9563. {
  9564. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9565. for(int idx = 0;idx<gunTotalNumber;idx++)
  9566. {
  9567. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9568. {
  9569. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9570. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9571. if(json_object_object_get(data, "description") != NULL)
  9572. {
  9573. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9574. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9575. }
  9576. else
  9577. {
  9578. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9579. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9580. }
  9581. }
  9582. }
  9583. }
  9584. else if(json_object_object_get(data, "transactionId") != NULL)
  9585. {
  9586. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9587. for(int idx = 0;idx<gunTotalNumber;idx++)
  9588. {
  9589. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9590. {
  9591. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9592. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9593. if(json_object_object_get(data, "cost") != NULL)
  9594. {
  9595. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  9596. ShmOCPP16DataPH->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9597. }
  9598. else
  9599. {
  9600. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9601. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9602. }
  9603. if(json_object_object_get(data, "priceText") != NULL)
  9604. {
  9605. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9606. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9607. }
  9608. else
  9609. {
  9610. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9611. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  9612. }
  9613. if(json_object_object_get(data, "qrCodeText") != NULL)
  9614. {
  9615. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9616. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9617. }
  9618. }
  9619. }
  9620. }
  9621. else
  9622. {
  9623. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9624. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9625. }
  9626. }
  9627. else
  9628. {
  9629. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9630. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9631. }
  9632. json_object_put(data);
  9633. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9634. json_object_put(response);
  9635. }
  9636. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9637. {
  9638. json_object *data;
  9639. data = json_tokener_parse(tempdata);
  9640. if(!is_error(data))
  9641. {
  9642. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9643. if(json_object_object_get(data, "Content_Type") != NULL)
  9644. {
  9645. if((0 <= json_object_get_int(json_object_object_get(data, "Content_Type"))) && (json_object_get_int(json_object_object_get(data, "Content_Type")) <= 1))
  9646. {
  9647. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9648. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9649. {
  9650. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9651. }
  9652. }
  9653. else
  9654. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9655. }
  9656. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9657. }
  9658. else
  9659. {
  9660. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9661. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9662. }
  9663. json_object_put(data);
  9664. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9665. json_object_put(response);
  9666. }
  9667. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9668. {
  9669. json_object *data;
  9670. data = json_tokener_parse(tempdata);
  9671. if(!is_error(data))
  9672. {
  9673. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9674. if(json_object_object_get(data, "ConnectorId") != NULL)
  9675. {
  9676. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9677. }
  9678. if(json_object_object_get(data, "SerialNo") != NULL)
  9679. {
  9680. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9681. }
  9682. if(json_object_object_get(data, "Page_Index") != NULL)
  9683. {
  9684. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9685. }
  9686. if(json_object_object_get(data, "Duration") != NULL)
  9687. {
  9688. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9689. }
  9690. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9691. }
  9692. else
  9693. {
  9694. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9695. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9696. }
  9697. json_object_put(data);
  9698. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9699. json_object_put(response);
  9700. }
  9701. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9702. {
  9703. json_object *data;
  9704. data = json_tokener_parse(tempdata);
  9705. if(!is_error(data))
  9706. {
  9707. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9708. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9709. {
  9710. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9711. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9712. else
  9713. {
  9714. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9715. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9716. }
  9717. }
  9718. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9719. {
  9720. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9721. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9722. else
  9723. {
  9724. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9725. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9726. }
  9727. }
  9728. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9729. {
  9730. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9731. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9732. else
  9733. {
  9734. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9735. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9736. }
  9737. }
  9738. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9739. {
  9740. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9741. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9742. else
  9743. {
  9744. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9745. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9746. }
  9747. }
  9748. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9749. {
  9750. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9751. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9752. else
  9753. {
  9754. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9755. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9756. }
  9757. }
  9758. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9759. {
  9760. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9761. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9762. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9763. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9764. else
  9765. {
  9766. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9767. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9768. }
  9769. }
  9770. if(json_object_object_get(data, "isAuthentication") != NULL)
  9771. {
  9772. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9773. {
  9774. case 0:
  9775. case 1:
  9776. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9777. break;
  9778. default:
  9779. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9780. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9781. break;
  9782. }
  9783. }
  9784. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9785. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9786. }
  9787. else
  9788. {
  9789. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9790. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9791. }
  9792. json_object_put(data);
  9793. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9794. json_object_put(response);
  9795. }
  9796. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9797. {
  9798. json_object *data;
  9799. data = json_tokener_parse(tempdata);
  9800. if(!is_error(data))
  9801. {
  9802. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9803. if(json_object_object_get(data, "stationName") != NULL)
  9804. {
  9805. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9806. }
  9807. else
  9808. {
  9809. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9810. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9811. }
  9812. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9813. {
  9814. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9815. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9816. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9817. }
  9818. }
  9819. else
  9820. {
  9821. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9822. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9823. }
  9824. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9825. json_object_put(response);
  9826. }
  9827. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9828. {
  9829. json_object *data;
  9830. data = json_tokener_parse(tempdata);
  9831. if(!is_error(data))
  9832. {
  9833. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9834. if(json_object_object_get(data, "weatherId") != NULL)
  9835. {
  9836. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9837. }
  9838. else
  9839. {
  9840. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9841. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9842. }
  9843. if(json_object_object_get(data, "Temperature") != NULL)
  9844. {
  9845. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9846. }
  9847. else
  9848. {
  9849. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9850. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9851. }
  9852. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9853. {
  9854. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9855. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9856. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9857. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9858. }
  9859. }
  9860. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9861. {
  9862. json_object *data;
  9863. data = json_tokener_parse(tempdata);
  9864. if(!is_error(data))
  9865. {
  9866. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9867. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9868. {
  9869. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9870. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9871. }
  9872. else
  9873. {
  9874. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9875. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9876. }
  9877. }
  9878. else
  9879. {
  9880. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9881. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9882. }
  9883. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9884. json_object_put(response);
  9885. }
  9886. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9887. {
  9888. json_object *data;
  9889. data = json_tokener_parse(tempdata);
  9890. if(!is_error(data))
  9891. {
  9892. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9893. {
  9894. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9895. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9896. if(gun_index < gunTotalNumber)
  9897. {
  9898. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9899. {
  9900. json_object *responsedata = json_object_new_object();
  9901. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9902. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9903. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9904. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9905. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9906. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9907. }
  9908. else
  9909. {
  9910. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9911. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9912. }
  9913. }
  9914. else
  9915. {
  9916. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9917. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9918. }
  9919. }
  9920. else
  9921. {
  9922. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9923. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9924. }
  9925. }
  9926. else
  9927. {
  9928. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9929. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9930. }
  9931. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9932. json_object_put(response);
  9933. }
  9934. else
  9935. {
  9936. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9937. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9938. }
  9939. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9940. json_object_put(response);
  9941. }
  9942. else
  9943. {
  9944. // Can not find valid message id
  9945. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9946. }
  9947. }
  9948. else
  9949. {
  9950. // Payload is null
  9951. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9952. }
  9953. LWS_Send(message);
  9954. return result;
  9955. }
  9956. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9957. {
  9958. mtrace();
  9959. int result = FAIL;
  9960. int connectorIdInt, durationInt;
  9961. char chargingRateUnitStr[4]={0};
  9962. char comfirmstr[20];
  9963. int confirmPeriods = 0;
  9964. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9965. json_object *GetCompositeSchedule;
  9966. GetCompositeSchedule = json_tokener_parse(payload);
  9967. if(!is_error(GetCompositeSchedule))
  9968. {
  9969. // Required data
  9970. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9971. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9972. else
  9973. connectorIdInt = -1;
  9974. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9975. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9976. else
  9977. durationInt = 86400;
  9978. // Optional data
  9979. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9980. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9981. }
  9982. json_object_put(GetCompositeSchedule);
  9983. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9984. if((connectorIdInt == 0) ||
  9985. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9986. {
  9987. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9988. struct StructChargingProfile tmpProfile[1];
  9989. if(strstr(chargingRateUnitStr, "W") != NULL)
  9990. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9991. else
  9992. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9993. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9994. {
  9995. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9996. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9997. }
  9998. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9999. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10000. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10001. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10002. {
  10003. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10004. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10005. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10006. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10007. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10008. {
  10009. confirmPeriods = idx;
  10010. break;
  10011. }
  10012. }
  10013. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10014. {
  10015. confirmPeriods += 1;
  10016. }
  10017. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10018. }
  10019. else
  10020. {
  10021. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10022. }
  10023. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10024. return result;
  10025. }
  10026. int handleGetConfigurationRequest(char *uuid, char *payload)
  10027. {
  10028. mtrace();
  10029. int result = FAIL;
  10030. int MaxKeySupported = 0;
  10031. int n_keys = 0;
  10032. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10033. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10034. json_object *GetConfiguration;
  10035. GetConfiguration = json_tokener_parse(payload);
  10036. if(!is_error(GetConfiguration))
  10037. {
  10038. // Optional data
  10039. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10040. {
  10041. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10042. {
  10043. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10044. n_keys = idx + 1;
  10045. }
  10046. }
  10047. }
  10048. json_object_put(GetConfiguration);
  10049. UnknownKeynum = 0;
  10050. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10051. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10052. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10053. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10054. if(n_keys != 0)
  10055. {
  10056. for(int i=0;i<n_keys;i++)
  10057. {
  10058. getKeyValue(requestKey[i]);
  10059. }
  10060. }
  10061. else
  10062. {
  10063. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10064. getKeyValue("");
  10065. }
  10066. processUnkownKey();
  10067. sendGetConfigurationConfirmation(uuid);
  10068. return result;
  10069. }
  10070. static char fnamePlusPath[100]={0};
  10071. static char fnamePWithNoPath[60]={0};
  10072. void checkUploadLog(void)
  10073. {
  10074. FILE *fp;
  10075. /* Open the command for reading. */
  10076. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10077. if (fp == NULL) {
  10078. DEBUG_WARN("Failed to run command\n" );
  10079. exit(1);
  10080. }
  10081. int ftppathlen = 0;
  10082. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10083. int i = 0;
  10084. /* Read the output a line at a time - output it. */
  10085. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10086. if(i==0)
  10087. {
  10088. ftppathlen = strlen(fnamePlusPath);
  10089. DEBUG_INFO("%s\n", fnamePlusPath);
  10090. fnamePlusPath[ftppathlen]='\0';
  10091. break;
  10092. }
  10093. i= i+1;
  10094. }
  10095. /* close */
  10096. pclose(fp);
  10097. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10098. {
  10099. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10100. {
  10101. fnamePlusPath[k]='\0';
  10102. }
  10103. }
  10104. i=1;
  10105. //char fname[60]={0};
  10106. while(i < ftppathlen)
  10107. {
  10108. int len=ftppathlen-i;
  10109. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10110. {
  10111. DEBUG_INFO("compare '/' all right\n");
  10112. break;
  10113. }
  10114. i=i+1;
  10115. }
  10116. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10117. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10118. fnamePWithNoPath[i+1] = '\0';
  10119. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10120. {
  10121. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10122. {
  10123. fnamePWithNoPath[j]='\0';
  10124. }
  10125. }
  10126. FILE* fp1 = fopen(fnamePlusPath, "r");
  10127. if (fp1)
  10128. {
  10129. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10130. // file exists
  10131. fclose(fp1);
  10132. }
  10133. else
  10134. {
  10135. // file doesn't exist
  10136. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10137. }
  10138. }
  10139. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10140. {
  10141. mtrace();
  10142. int result = FAIL;
  10143. time_t CurrentTime;
  10144. struct tm *tm;
  10145. pthread_t th_Status;
  10146. CurrentTime = time(NULL);
  10147. tm = localtime(&CurrentTime);
  10148. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  10149. sprintf((char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, "%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  10150. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10151. if(!interLock.isGetDiagnosticGoing)
  10152. {
  10153. interLock.isGetDiagnosticGoing = 1;
  10154. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10155. sleep(1);
  10156. }
  10157. else
  10158. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10159. return result;
  10160. }
  10161. void* GetDiagnosticsProcess(void* data)
  10162. {
  10163. pthread_detach(pthread_self());
  10164. mtrace();
  10165. int retriesInt=0, retryIntervalInt=0;
  10166. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10167. char protocol[10]={0}, user[64]={0},password[128]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  10168. int port=0;
  10169. int isSuccess = FALSE;
  10170. char ftpbuf[200]={0};
  10171. char cmdBuf[2048];
  10172. struct tm *tmNow;
  10173. time_t CurrentTime;
  10174. struct tm tmStart;
  10175. struct tm tmStop;
  10176. CurrentTime = time(NULL);
  10177. tmNow=localtime(&CurrentTime);
  10178. uint16_t targetYear, targetMonth;
  10179. json_object *GetDiagnostics;
  10180. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10181. GetDiagnostics = json_tokener_parse(data);
  10182. if(!is_error(GetDiagnostics))
  10183. {
  10184. // Required data
  10185. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10186. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10187. // Optional data
  10188. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10189. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10190. else
  10191. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10192. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10193. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10194. else
  10195. retryIntervalInt = 30;
  10196. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10197. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10198. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10199. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10200. }
  10201. json_object_put(GetDiagnostics);
  10202. // Pack log to compress file
  10203. if((sscanf((char*)startTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  10204. (sscanf((char*)stopTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  10205. {
  10206. // Pack system log
  10207. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10208. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10209. targetYear = tmStart.tm_year;
  10210. targetMonth = tmStart.tm_mon;
  10211. do
  10212. {
  10213. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10214. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10215. if(targetMonth+1>=13)
  10216. {
  10217. targetYear += 1;
  10218. targetMonth = 1;
  10219. }
  10220. else
  10221. {
  10222. targetMonth += 1;
  10223. }
  10224. }while((targetYear < (tmNow->tm_year+1900)) ||
  10225. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10226. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10227. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10228. system(cmdBuf);
  10229. // Pack charging & event log
  10230. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10231. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10232. targetYear = tmStart.tm_year;
  10233. targetMonth = tmStart.tm_mon;
  10234. do
  10235. {
  10236. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10237. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10238. if(targetMonth+1>=13)
  10239. {
  10240. targetYear += 1;
  10241. targetMonth = 1;
  10242. }
  10243. else
  10244. {
  10245. targetMonth += 1;
  10246. }
  10247. }while((targetYear < (tmNow->tm_year+1900)) ||
  10248. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10249. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10250. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10251. system(cmdBuf);
  10252. // Combine log file
  10253. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10254. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10255. }
  10256. else
  10257. {
  10258. system("exec /root/logPackTools 'log' 6");
  10259. }
  10260. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10261. system(cmdBuf);
  10262. checkUploadLog();
  10263. //****************location*******************/
  10264. if(strcmp(locationstr,"")==0)
  10265. {
  10266. DEBUG_INFO("location is <Empty>!\n");
  10267. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10268. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10269. goto end;
  10270. }
  10271. memset(protocol, 0, ARRAY_SIZE(protocol));
  10272. memset(user, 0, ARRAY_SIZE(user) );
  10273. memset(password, 0, ARRAY_SIZE(password));
  10274. memset(host, 0, ARRAY_SIZE(host));
  10275. memset(path, 0, ARRAY_SIZE(path));
  10276. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10277. memset(host1, 0, ARRAY_SIZE(host1));
  10278. memset(path1, 0, ARRAY_SIZE(path1));
  10279. /*location: ftp://user:password@host:port/path*/
  10280. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10281. if((access(fnamePlusPath,F_OK))!=-1)
  10282. {
  10283. DEBUG_INFO("fnamePlusPath exist.\n");
  10284. }
  10285. else
  10286. {
  10287. DEBUG_INFO("fnamePlusPath not exist!\n");
  10288. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10289. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10290. goto end;
  10291. }
  10292. if(strchr(locationstr,'@')==NULL)
  10293. {
  10294. sscanf(locationstr,
  10295. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10296. protocol, host, &port, path);
  10297. strcpy(user,"anonymous");
  10298. strcpy(password,"");
  10299. }
  10300. else
  10301. {
  10302. //DEBUG_INFO("pch=%s\n", pch);
  10303. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10304. protocol, user, password, host, &port, path);
  10305. }
  10306. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10307. {
  10308. DEBUG_INFO("protocol is not ftp/http ! \n");
  10309. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10310. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10311. goto end;
  10312. }
  10313. if(strncmp(locationstr,"http", 4) == 0)
  10314. {
  10315. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10316. sprintf(ftppath,"/%s", path);
  10317. do
  10318. {
  10319. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10320. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10321. sleep(3);
  10322. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10323. if(!isSuccess)
  10324. {
  10325. DEBUG_INFO("Diagnostics fail.\n");
  10326. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10327. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10328. sleep(retryIntervalInt);
  10329. }
  10330. else
  10331. {
  10332. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10333. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10334. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10335. }
  10336. retriesInt--;
  10337. }while((isSuccess == 0)&&(retriesInt >= 0));
  10338. }
  10339. else
  10340. {
  10341. sscanf(host,"%[^/]%s",host1, path1);
  10342. if(strlen(path) > 0)
  10343. sprintf(ftppath,"/%s", path);
  10344. else
  10345. sprintf(ftppath,"/%s", path1);
  10346. int ftppathlen=strlen(ftppath);
  10347. int i=1;
  10348. char filenametemp[50];
  10349. while(i < ftppathlen)
  10350. {
  10351. int len=ftppathlen-i;
  10352. if(ftppath[len]== 47) // '/' ascll code: 47
  10353. {
  10354. DEBUG_INFO("find '/' all right\n");
  10355. break;
  10356. }
  10357. i=i+1;
  10358. }
  10359. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10360. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10361. filenametemp[i+1] = 0;
  10362. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10363. if(port == 0)
  10364. port = 21;
  10365. do
  10366. {
  10367. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10368. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10369. sleep(3);
  10370. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10371. if(!isSuccess)
  10372. {
  10373. DEBUG_INFO("Diagnostics fail.\n");
  10374. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10375. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10376. sleep(retryIntervalInt);
  10377. }
  10378. else
  10379. {
  10380. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10381. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10382. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10383. }
  10384. retriesInt--;
  10385. }while((!isSuccess)&&(retriesInt >= 0));
  10386. }
  10387. end:
  10388. system("rm -f /mnt/*");
  10389. sleep(5);
  10390. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10391. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10392. interLock.isGetDiagnosticGoing = 0;
  10393. pthread_exit(NULL);
  10394. }
  10395. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10396. {
  10397. mtrace();
  10398. int result = FAIL;
  10399. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10400. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10401. {
  10402. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10403. locallistVersion = -1;
  10404. }
  10405. else
  10406. {
  10407. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10408. locallistVersion = 0;
  10409. OCPP_getListVerion();
  10410. }
  10411. //from db.OCPP_getListVerion
  10412. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10413. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10414. sendGetLocalListVersionConfirmation(uuid,"");
  10415. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10416. return result;
  10417. }
  10418. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10419. {
  10420. mtrace();
  10421. int result = FAIL;
  10422. int connectorIdInt=-1;
  10423. int tempIndex = 0;
  10424. int connectorIdIsNULL, chargingProfileIsNULL;
  10425. char comfirmstr[20]={0};
  10426. char cmdBuf[512];
  10427. json_object *RemoteStartTransaction;
  10428. FILE *fp;
  10429. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10430. if(server_pending == TRUE)
  10431. {
  10432. return 0;
  10433. }
  10434. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10435. RemoteStartTransaction = json_tokener_parse(payload);
  10436. if(!is_error(RemoteStartTransaction))
  10437. {
  10438. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10439. {
  10440. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10441. }
  10442. else
  10443. {
  10444. connectorIdIsNULL = TRUE;
  10445. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10446. {
  10447. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10448. {
  10449. connectorIdIsNULL = FALSE;
  10450. connectorIdInt = (gun_index+1);
  10451. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10452. break;
  10453. }
  10454. }
  10455. }
  10456. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10457. {
  10458. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10459. // Required data
  10460. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10461. // Optional data
  10462. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10463. {
  10464. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10465. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10466. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10467. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10468. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10469. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10470. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10471. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10472. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10473. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10474. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10475. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10476. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10477. {
  10478. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10479. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10480. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10481. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10482. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10483. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10484. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10485. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10486. {
  10487. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  10488. {
  10489. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10490. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10491. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  10492. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10493. }
  10494. }
  10495. }
  10496. }
  10497. else
  10498. {
  10499. chargingProfileIsNULL = TRUE;
  10500. }
  10501. }
  10502. }
  10503. else
  10504. {
  10505. connectorIdIsNULL = TRUE;
  10506. }
  10507. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10508. {
  10509. DEBUG_WARN("Connector id is NULL\n.");
  10510. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10511. goto end;
  10512. }
  10513. /*
  10514. enum _SYSTEM_STATUS
  10515. {
  10516. S_BOOTING = 0,
  10517. S_IDLE, = 1
  10518. S_AUTHORIZING, = 2
  10519. S_REASSIGN_CHECK, = 3
  10520. S_REASSIGN, = 4
  10521. S_PRECHARGE, = 5
  10522. S_PREPARING_FOR_EV, = 6
  10523. S_PREPARING_FOR_EVSE, = 7
  10524. S_CHARGING, = 8
  10525. S_TERMINATING, = 9
  10526. S_COMPLETE, = 10
  10527. S_ALARM, = 11
  10528. S_FAULT = 12
  10529. }
  10530. */
  10531. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10532. {
  10533. //check Transaction active
  10534. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10535. {
  10536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10537. {
  10538. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10539. }
  10540. else
  10541. {
  10542. tempIndex = connectorIdInt -1;
  10543. }
  10544. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10545. {
  10546. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10547. {
  10548. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10549. {
  10550. //Reserved
  10551. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10552. }
  10553. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10554. {
  10555. //Reserved
  10556. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10557. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10558. goto end;
  10559. }
  10560. else
  10561. {
  10562. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10563. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10564. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10565. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10566. {
  10567. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10568. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10569. goto end;
  10570. }
  10571. }//END FOR ELSE
  10572. }
  10573. }// END FOR CHAdeMO_QUANTITY
  10574. }
  10575. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10576. {
  10577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10578. {
  10579. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10580. }
  10581. else
  10582. {
  10583. tempIndex = connectorIdInt -1;
  10584. }
  10585. for (int index = 0; index < CCS_QUANTITY; index++)
  10586. {
  10587. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10588. {
  10589. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10590. {
  10591. //Reserved
  10592. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10593. }
  10594. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10595. {
  10596. //Reserved
  10597. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10598. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10599. goto end;
  10600. }
  10601. else
  10602. {
  10603. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10604. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10605. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10606. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10607. {
  10608. DEBUG_WARN("CCS connector not allow start\n.");
  10609. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10610. goto end;
  10611. }
  10612. }// END FOR ELSE
  10613. }
  10614. }// END FOR CCS_QUANTITY
  10615. }
  10616. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10617. {
  10618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10619. {
  10620. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10621. }
  10622. else
  10623. {
  10624. tempIndex = connectorIdInt -1;
  10625. }
  10626. for (int index = 0; index < GB_QUANTITY; index++)
  10627. {
  10628. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10629. {
  10630. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10631. {
  10632. //Reserved
  10633. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10634. }
  10635. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10636. {
  10637. //Reserved
  10638. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10639. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10640. goto end;
  10641. }
  10642. else
  10643. {
  10644. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10645. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10646. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10647. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10648. {
  10649. DEBUG_WARN("GB connector not allow start\n.");
  10650. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10651. goto end;
  10652. }
  10653. }// END FOR ELSE
  10654. }
  10655. } // END FOR GB_QUANTITY
  10656. }
  10657. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10658. {
  10659. tempIndex = connectorIdInt -1;
  10660. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10661. {
  10662. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10663. {
  10664. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10665. {
  10666. //Reserved
  10667. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10668. }
  10669. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10670. {
  10671. //Reserved
  10672. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10673. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10674. goto end;
  10675. }
  10676. else
  10677. {
  10678. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10679. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10680. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10681. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10682. {
  10683. DEBUG_WARN("GB connector not allow start\n.");
  10684. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10685. goto end;
  10686. }
  10687. }// END FOR ELSE
  10688. }
  10689. } // END FOR GB_QUANTITY
  10690. }
  10691. else
  10692. {
  10693. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10694. {
  10695. tempIndex = 2;
  10696. }
  10697. else
  10698. {
  10699. tempIndex = connectorIdInt -1;
  10700. }
  10701. for (int index = 0; index < AC_QUANTITY; index++)
  10702. {
  10703. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10704. {
  10705. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10706. {
  10707. //Reserved
  10708. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10709. }
  10710. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10711. {
  10712. //Reserved
  10713. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10714. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10715. goto end;
  10716. }
  10717. else
  10718. {
  10719. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10720. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10721. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10722. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10723. {
  10724. DEBUG_WARN("AC connector not allow start\n.");
  10725. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10726. goto end;
  10727. }
  10728. }//END FOR ELSE
  10729. }
  10730. }// END FOR AC_QUANTITY
  10731. }
  10732. if(chargingProfileIsNULL == FALSE)
  10733. {
  10734. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10735. {
  10736. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10737. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10738. //memset idTag
  10739. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10740. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10741. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10742. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10743. // Save profile to file
  10744. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10745. system(cmdBuf);
  10746. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10747. fp = fopen(cmdBuf, "w");
  10748. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10749. fclose(fp);
  10750. }
  10751. else
  10752. {
  10753. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10754. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10755. }
  10756. }
  10757. else
  10758. {
  10759. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10760. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10761. //memset idTag
  10762. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10763. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10764. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10765. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10766. }
  10767. }
  10768. else
  10769. {
  10770. DEBUG_WARN("Connector id over\n.");
  10771. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10772. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10773. }
  10774. end:
  10775. json_object_put(RemoteStartTransaction);
  10776. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10777. {
  10778. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10779. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10780. }
  10781. //OCPP send RemoteStartConfirmation by first.
  10782. sendRemoteStartConfirmation(uuid, comfirmstr);
  10783. return result;
  10784. }
  10785. int handleRemoteStartRequest(char *uuid, char *payload)
  10786. {
  10787. mtrace();
  10788. int result = PASS;
  10789. int connectorIdInt=-1;
  10790. int tempIndex = 0;
  10791. char comfirmstr[20]={0};
  10792. char cmdBuf[512];
  10793. json_object *RemoteStartTransaction;
  10794. FILE *fp;
  10795. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10796. if(server_pending == TRUE)
  10797. {
  10798. result = FAIL;
  10799. }
  10800. RemoteStartTransaction = json_tokener_parse(payload);
  10801. if(!is_error(RemoteStartTransaction))
  10802. {
  10803. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10804. {
  10805. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10806. }
  10807. else
  10808. {
  10809. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10810. {
  10811. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10812. {
  10813. connectorIdInt = (gun_index+1);
  10814. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10815. break;
  10816. }
  10817. }
  10818. }
  10819. if(connectorIdInt == 0)
  10820. {
  10821. DEBUG_WARN("Connector id shall not equal 0.\n");
  10822. result = FAIL;
  10823. }
  10824. else if(connectorIdInt == -1)
  10825. {
  10826. DEBUG_INFO("Connector id does not specific.\n");
  10827. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10828. {
  10829. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10830. // Required data
  10831. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10832. // Optional data
  10833. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10834. {
  10835. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10836. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10837. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10838. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10839. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10840. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10841. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10842. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10843. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10844. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10845. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10846. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10847. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10848. {
  10849. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10850. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10851. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10852. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10853. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10854. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10855. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10856. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10857. {
  10858. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  10859. {
  10860. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10861. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10862. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  10863. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10864. }
  10865. }
  10866. }
  10867. }
  10868. else
  10869. {
  10870. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10871. }
  10872. }
  10873. }
  10874. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10875. {
  10876. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10877. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10878. // Required data
  10879. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10880. // Optional data
  10881. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10882. {
  10883. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10884. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10885. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10886. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10887. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10888. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10889. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10890. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10891. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10892. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10893. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10894. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10895. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10896. {
  10897. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10898. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10899. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10900. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10901. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10902. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10903. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10904. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10905. {
  10906. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  10907. {
  10908. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10909. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10910. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  10911. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10912. }
  10913. }
  10914. }
  10915. }
  10916. else
  10917. {
  10918. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10919. }
  10920. }
  10921. else
  10922. {
  10923. DEBUG_WARN("Connector id is over maximun value.\n");
  10924. result = FAIL;
  10925. }
  10926. }
  10927. if(result == PASS)
  10928. {
  10929. if(connectorIdInt > 0)
  10930. {
  10931. //check Transaction active
  10932. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10933. {
  10934. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10935. {
  10936. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10937. }
  10938. else
  10939. {
  10940. tempIndex = connectorIdInt -1;
  10941. }
  10942. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10943. {
  10944. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10945. {
  10946. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10947. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10948. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10949. {
  10950. //Reserved
  10951. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10952. }
  10953. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10954. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10955. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10956. {
  10957. //Reserved
  10958. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10959. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10960. goto end;
  10961. }
  10962. else
  10963. {
  10964. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10965. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10966. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10967. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10968. {
  10969. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10970. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10971. goto end;
  10972. }
  10973. }//END FOR ELSE
  10974. }
  10975. }// END FOR CHAdeMO_QUANTITY
  10976. }
  10977. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10978. {
  10979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10980. {
  10981. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10982. }
  10983. else
  10984. {
  10985. tempIndex = connectorIdInt -1;
  10986. }
  10987. for (int index = 0; index < CCS_QUANTITY; index++)
  10988. {
  10989. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10990. {
  10991. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10992. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10993. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10994. {
  10995. //Reserved
  10996. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10997. }
  10998. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10999. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11000. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11001. {
  11002. //Reserved
  11003. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11004. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11005. goto end;
  11006. }
  11007. else
  11008. {
  11009. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11010. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11011. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11012. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11013. {
  11014. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11015. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11016. goto end;
  11017. }
  11018. }// END FOR ELSE
  11019. }
  11020. }// END FOR CCS_QUANTITY
  11021. }
  11022. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11023. {
  11024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11025. {
  11026. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11027. }
  11028. else
  11029. {
  11030. tempIndex = connectorIdInt -1;
  11031. }
  11032. for (int index = 0; index < GB_QUANTITY; index++)
  11033. {
  11034. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11035. {
  11036. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11037. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11038. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11039. {
  11040. //Reserved
  11041. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11042. }
  11043. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11044. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11045. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11046. {
  11047. //Reserved
  11048. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11049. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11050. goto end;
  11051. }
  11052. else
  11053. {
  11054. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11055. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11056. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11057. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11058. {
  11059. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11060. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11061. goto end;
  11062. }
  11063. }// END FOR ELSE
  11064. }
  11065. } // END FOR GB_QUANTITY
  11066. }
  11067. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11068. {
  11069. tempIndex = connectorIdInt -1;
  11070. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11071. {
  11072. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11073. {
  11074. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11075. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11076. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11077. {
  11078. //Reserved
  11079. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11080. }
  11081. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11082. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11083. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11084. {
  11085. //Reserved
  11086. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11087. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11088. goto end;
  11089. }
  11090. else
  11091. {
  11092. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11093. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11094. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11095. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11096. {
  11097. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11098. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11099. goto end;
  11100. }
  11101. }// END FOR ELSE
  11102. }
  11103. } // END FOR GB_QUANTITY
  11104. }
  11105. else
  11106. {
  11107. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11108. {
  11109. tempIndex = 2;
  11110. }
  11111. else
  11112. {
  11113. tempIndex = connectorIdInt -1;
  11114. }
  11115. for (int index = 0; index < AC_QUANTITY; index++)
  11116. {
  11117. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11118. {
  11119. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11120. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11121. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11122. {
  11123. //Reserved
  11124. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11125. }
  11126. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11127. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11128. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11129. {
  11130. //Reserved
  11131. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11132. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11133. goto end;
  11134. }
  11135. else
  11136. {
  11137. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11138. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11139. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11140. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11141. {
  11142. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11143. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11144. goto end;
  11145. }
  11146. }//END FOR ELSE
  11147. }
  11148. }// END FOR AC_QUANTITY
  11149. }
  11150. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11151. {
  11152. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11153. {
  11154. // Save profile to file
  11155. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  11156. system(cmdBuf);
  11157. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  11158. fp = fopen(cmdBuf, "w");
  11159. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11160. fclose(fp);
  11161. }
  11162. else
  11163. {
  11164. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11165. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11166. goto end;
  11167. }
  11168. }
  11169. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11170. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11171. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11172. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11173. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11174. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11175. }
  11176. else
  11177. {
  11178. uint8_t isHasIdleConnector = FALSE;
  11179. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11180. {
  11181. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11182. {
  11183. isHasIdleConnector = TRUE;
  11184. break;
  11185. }
  11186. }
  11187. if(isHasIdleConnector == TRUE)
  11188. {
  11189. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11190. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11191. {
  11192. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11193. {
  11194. // Save profile to file
  11195. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  11196. system(cmdBuf);
  11197. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  11198. fp = fopen(cmdBuf, "w");
  11199. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11200. fclose(fp);
  11201. refreshStartTimer(&clientTime.RemoteStartWait);
  11202. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  11203. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11204. }
  11205. else
  11206. {
  11207. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11208. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11209. }
  11210. }
  11211. else
  11212. {
  11213. refreshStartTimer(&clientTime.RemoteStartWait);
  11214. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  11215. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11216. }
  11217. }
  11218. else
  11219. {
  11220. DEBUG_INFO("There is not any connector is idle.\n");
  11221. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11222. }
  11223. }
  11224. }
  11225. else
  11226. {
  11227. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11228. }
  11229. end:
  11230. json_object_put(RemoteStartTransaction);
  11231. sendRemoteStartConfirmation(uuid, comfirmstr);
  11232. return result;
  11233. }
  11234. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11235. {
  11236. mtrace();
  11237. int result = FAIL;
  11238. int match = FALSE;
  11239. int GunNO = 0;
  11240. int tempIndex = 0;
  11241. int transactionIdInt=0;
  11242. int transactionIdIsNULL= TRUE;
  11243. char comfirmstr[20];
  11244. json_object *RemoteStopTransaction;
  11245. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11246. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11247. if(server_pending == TRUE)
  11248. {
  11249. return 0;
  11250. }
  11251. RemoteStopTransaction = json_tokener_parse(payload);
  11252. if(!is_error(RemoteStopTransaction))
  11253. {
  11254. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11255. {
  11256. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11257. transactionIdIsNULL = FALSE;
  11258. }
  11259. }
  11260. json_object_put(RemoteStopTransaction);
  11261. if(transactionIdIsNULL == FALSE)
  11262. {
  11263. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11264. {
  11265. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11266. {
  11267. //check Transaction active
  11268. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11269. {
  11270. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11271. {
  11272. tempIndex = ((gun_index==2) ? 1: 0);
  11273. }
  11274. else
  11275. {
  11276. tempIndex = gun_index;
  11277. }
  11278. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11279. {
  11280. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11281. {
  11282. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11283. {
  11284. match = TRUE;
  11285. GunNO = gun_index;
  11286. }
  11287. }
  11288. }// END FOR CHAdeMO_QUANTITY
  11289. }
  11290. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11291. {
  11292. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11293. {
  11294. tempIndex = ((gun_index==2) ? 1: 0);
  11295. }
  11296. else
  11297. {
  11298. tempIndex = gun_index;
  11299. }
  11300. for (int index = 0; index < CCS_QUANTITY; index++)
  11301. {
  11302. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11303. {
  11304. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11305. {
  11306. match = TRUE;
  11307. GunNO = gun_index;
  11308. }
  11309. }
  11310. }// END FOR CCS_QUANTITY
  11311. }
  11312. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11313. {
  11314. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11315. {
  11316. tempIndex = ((gun_index==2) ? 1: 0);
  11317. }
  11318. else
  11319. {
  11320. tempIndex = gun_index;
  11321. }
  11322. for (int index = 0; index < GB_QUANTITY; index++)
  11323. {
  11324. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11325. {
  11326. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11327. {
  11328. match = TRUE;
  11329. GunNO = gun_index;
  11330. }
  11331. }
  11332. }// END FOR GB_QUANTITY
  11333. }
  11334. else if(gunType[gun_index] == GUN_TYPE_DO)
  11335. {
  11336. tempIndex = gun_index;
  11337. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11338. {
  11339. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11340. {
  11341. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11342. {
  11343. match = TRUE;
  11344. GunNO = gun_index;
  11345. }
  11346. }
  11347. }// END FOR GB_QUANTITY
  11348. }
  11349. else
  11350. {
  11351. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11352. {
  11353. tempIndex = 2;
  11354. }
  11355. else
  11356. {
  11357. tempIndex = gun_index;
  11358. }
  11359. for (int index = 0; index < AC_QUANTITY; index++)
  11360. {
  11361. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11362. {
  11363. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11364. {
  11365. match = TRUE;
  11366. GunNO = gun_index;
  11367. }
  11368. }
  11369. }// END FOR CHAdeMO_QUANTITY
  11370. } // END FOR AC ELSE
  11371. }// CHECK IF ResponseTransactionId == transactionIdInt
  11372. }//END FOR
  11373. if( match == TRUE)
  11374. {
  11375. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11376. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11377. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11378. }
  11379. else
  11380. {
  11381. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11382. }
  11383. }
  11384. else
  11385. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11386. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11387. return result;
  11388. }
  11389. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11390. {
  11391. mtrace();
  11392. int result = FAIL;
  11393. int connectorIdInt=0, reservationIdInt=0;
  11394. int tempIndex = 0;
  11395. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11396. char comfirmstr[20]={0};
  11397. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11398. int c = 0;
  11399. char *loc;
  11400. //char *ptr;
  11401. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11402. strcpy(sstrtemp, stringtrimspace(payload));
  11403. //***(1)connectorId ****/
  11404. c=0;
  11405. loc = strstr(sstrtemp, "connectorId");
  11406. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11407. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11408. {
  11409. sstr[c] = loc[strlen("connectorId")+2+c];
  11410. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11411. c++;
  11412. }
  11413. sstr[c] = '\0';
  11414. connectorIdInt = atoi(sstr);
  11415. //***(2)expiryDate ****/
  11416. loc = strstr(sstrtemp, "expiryDate");
  11417. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11418. c = 0;
  11419. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11420. {
  11421. sstr[c] = loc[3+strlen("expiryDate")+c];
  11422. c++;
  11423. }
  11424. sstr[c] = '\0';
  11425. strcpy(expiryDatestr, sstr);
  11426. //***(3)idTag ****/
  11427. loc = strstr(sstrtemp, "idTag");
  11428. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11429. c = 0;
  11430. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11431. {
  11432. sstr[c] = loc[3+strlen("idTag")+c];
  11433. c++;
  11434. }
  11435. sstr[c] = '\0';
  11436. strcpy(idTagstr, sstr);
  11437. //***(4)parentIdTag ****/
  11438. loc = strstr(sstrtemp, "parentIdTag");
  11439. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11440. c = 0;
  11441. if(loc == NULL)
  11442. {
  11443. strcpy(parentIdTagstr, "");
  11444. }
  11445. else
  11446. {
  11447. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11448. {
  11449. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11450. c++;
  11451. }
  11452. sstr[c] = '\0';
  11453. strcpy(parentIdTagstr, sstr);
  11454. }
  11455. //***(5)reservationId ****/
  11456. c=0;
  11457. loc = strstr(sstrtemp, "reservationId");
  11458. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11459. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11460. {
  11461. sstr[c] = loc[strlen("reservationId")+2+c];
  11462. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11463. c++;
  11464. }
  11465. sstr[c] = '\0';
  11466. reservationIdInt = atoi(sstr);
  11467. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11468. /*
  11469. enum SYSTEM_STATUS
  11470. {
  11471. SYS_MODE_BOOTING = 0,
  11472. SYS_MODE_IDLE = 1,
  11473. SYS_MODE_AUTHORIZING = 2,
  11474. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11475. SYS_MODE_REASSIGN = 4,
  11476. SYS_MODE_PREPARING = 5,
  11477. SYS_MODE_PREPARE_FOR_EV = 6,
  11478. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11479. SYS_MODE_CHARGING = 8,
  11480. SYS_MODE_TERMINATING = 9,
  11481. SYS_MODE_COMPLETE = 10,
  11482. SYS_MODE_ALARM = 11,
  11483. SYS_MODE_FAULT = 12,
  11484. SYS_MODE_RESERVATION = 13,
  11485. SYS_MODE_BOOKING = 14,
  11486. SYS_MODE_MAINTAIN = 15,
  11487. SYS_MODE_DEBUG = 16,
  11488. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11489. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11490. SYS_MODE_UPDATE = 19
  11491. };
  11492. */
  11493. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11494. {
  11495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11496. goto end;
  11497. }
  11498. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11499. {
  11500. //check Transaction active
  11501. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11502. {
  11503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11504. {
  11505. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11506. }
  11507. else
  11508. {
  11509. tempIndex = connectorIdInt -1;
  11510. }
  11511. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11512. {
  11513. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11514. {
  11515. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11516. {
  11517. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11518. {
  11519. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11520. {
  11521. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11522. {
  11523. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11524. }
  11525. else
  11526. {
  11527. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11528. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11529. }
  11530. }
  11531. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11532. {
  11533. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11534. }
  11535. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11536. {
  11537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11538. }
  11539. else
  11540. {
  11541. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11542. }
  11543. }
  11544. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  11545. {
  11546. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11547. }
  11548. }
  11549. else
  11550. {
  11551. //replace reservation
  11552. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11553. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11554. }
  11555. }
  11556. } // END FOR CHAdeMO_QUANTITY
  11557. }
  11558. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11559. {
  11560. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11561. {
  11562. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11563. }
  11564. else
  11565. {
  11566. tempIndex = connectorIdInt -1;
  11567. }
  11568. for (int index = 0; index < CCS_QUANTITY; index++)
  11569. {
  11570. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11571. {
  11572. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11573. {
  11574. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11575. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11576. {
  11577. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11578. {
  11579. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11580. {
  11581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11582. }
  11583. else
  11584. {
  11585. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11587. }
  11588. }
  11589. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  11590. {
  11591. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11592. }
  11593. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11594. {
  11595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11596. }
  11597. else
  11598. {
  11599. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11600. }
  11601. }
  11602. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAUL, SYS_MODE_TERMINATING ---> SuspendedEV
  11603. {
  11604. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11605. }
  11606. }
  11607. else
  11608. {
  11609. //replace reservation
  11610. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11612. }
  11613. }
  11614. } // END FOR CCS_QUANTITY
  11615. }
  11616. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11617. {
  11618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11619. {
  11620. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11621. }
  11622. else
  11623. {
  11624. tempIndex = connectorIdInt -1;
  11625. }
  11626. for (int index = 0; index < GB_QUANTITY; index++)
  11627. {
  11628. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11629. {
  11630. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11631. {
  11632. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11633. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11634. {
  11635. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11636. {
  11637. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11638. {
  11639. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11640. }
  11641. else
  11642. {
  11643. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11645. }
  11646. }
  11647. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  11648. {
  11649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11650. }
  11651. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11652. {
  11653. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11654. }
  11655. else
  11656. {
  11657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11658. }
  11659. }
  11660. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  11661. {
  11662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11663. }
  11664. }
  11665. else
  11666. {
  11667. //replace reservation
  11668. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11669. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11670. }
  11671. }
  11672. }// END FOR GB_QUANTITY
  11673. }
  11674. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11675. {
  11676. tempIndex = connectorIdInt -1;
  11677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11678. {
  11679. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11680. {
  11681. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11682. {
  11683. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11684. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11685. {
  11686. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11687. {
  11688. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11689. {
  11690. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11691. }
  11692. else
  11693. {
  11694. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11696. }
  11697. }
  11698. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  11699. {
  11700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11701. }
  11702. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11703. {
  11704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11705. }
  11706. else
  11707. {
  11708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11709. }
  11710. }
  11711. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  11712. {
  11713. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11714. }
  11715. }
  11716. else
  11717. {
  11718. //replace reservation
  11719. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11720. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11721. }
  11722. }
  11723. }// END FOR GB_QUANTITY
  11724. }
  11725. else
  11726. {
  11727. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11728. {
  11729. tempIndex = 2;
  11730. }
  11731. else
  11732. {
  11733. tempIndex = (connectorIdInt -1);
  11734. }
  11735. for (int index = 0; index < AC_QUANTITY; index++)
  11736. {
  11737. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11738. {
  11739. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11740. {
  11741. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11742. {
  11743. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11744. {
  11745. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  11746. {
  11747. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11748. }
  11749. else
  11750. {
  11751. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11753. }
  11754. }
  11755. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11756. {
  11757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11758. }
  11759. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11760. {
  11761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11762. }
  11763. else
  11764. {
  11765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11766. }
  11767. }
  11768. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  11769. {
  11770. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11771. }
  11772. }
  11773. else
  11774. {
  11775. //replace reservation
  11776. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11777. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11778. }
  11779. }
  11780. } // END FOR AC_QUANTITY
  11781. }
  11782. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11783. }
  11784. else if(connectorIdInt == 0)
  11785. {
  11786. //check Transaction active
  11787. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11788. {
  11789. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11790. {
  11791. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11792. {
  11793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11794. goto end;
  11795. }
  11796. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11797. {
  11798. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11799. goto end;
  11800. }
  11801. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11802. {
  11803. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11804. goto end;
  11805. }
  11806. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11807. {
  11808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11809. goto end;
  11810. }
  11811. }
  11812. }// END FOR CHAdeMO_QUANTITY
  11813. for (int index = 0; index < CCS_QUANTITY; index++)
  11814. {
  11815. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11816. {
  11817. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  11818. {
  11819. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11820. goto end;
  11821. }
  11822. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11823. {
  11824. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11825. goto end;
  11826. }
  11827. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11828. {
  11829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11830. goto end;
  11831. }
  11832. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11833. {
  11834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11835. goto end;
  11836. }
  11837. }
  11838. } // END FOR CCS_QUANTITY
  11839. for (int index = 0; index < GB_QUANTITY; index++)
  11840. {
  11841. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11842. {
  11843. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  11844. {
  11845. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11846. goto end;
  11847. }
  11848. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11849. {
  11850. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11851. goto end;
  11852. }
  11853. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING) ) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11854. {
  11855. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11856. goto end;
  11857. }
  11858. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11859. {
  11860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11861. goto end;
  11862. }
  11863. }
  11864. } // END FOR GB_QUANTITY
  11865. for (int index = 0; index < AC_QUANTITY; index++)
  11866. {
  11867. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11868. {
  11869. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11870. {
  11871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11872. goto end;
  11873. }
  11874. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11875. {
  11876. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11877. goto end;
  11878. }
  11879. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11880. {
  11881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11882. goto end;
  11883. }
  11884. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11885. {
  11886. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  11887. {
  11888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11889. goto end;
  11890. }
  11891. }
  11892. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11893. {
  11894. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11895. goto end;
  11896. }
  11897. }
  11898. }// END FOR AC_QUANTITY
  11899. //The connectorId is 0
  11900. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11901. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11902. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11903. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11904. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11905. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11906. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11907. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11908. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11909. result = TRUE;
  11910. return result;
  11911. }
  11912. else
  11913. {
  11914. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11915. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11916. }
  11917. if(strcmp(comfirmstr,"Accepted") == 0)
  11918. {
  11919. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11920. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11921. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11922. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11923. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11924. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11925. result = TRUE;
  11926. return result;
  11927. }
  11928. end:
  11929. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11930. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11931. return result;
  11932. }
  11933. int handleResetRequest(char *uuid, char *payload)
  11934. {
  11935. mtrace();
  11936. int result = FAIL;
  11937. char sstr[10]={0},sstrtemp[30]={ 0 };
  11938. char typestr[10]={0};
  11939. char comfirmstr[20]={0};
  11940. int c = 0;
  11941. char *loc;
  11942. DEBUG_INFO("handleResetRequest...\n");
  11943. strcpy(sstrtemp, stringtrimspace(payload));
  11944. loc = strstr(sstrtemp, "type");
  11945. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11946. c = 0;
  11947. while (loc[3+strlen("type")+c] != '\"')
  11948. {
  11949. sstr[c] = loc[3+strlen("type")+c];
  11950. c++;
  11951. }
  11952. sstr[c] = '\0';
  11953. strcpy(typestr,sstr);
  11954. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11955. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11956. {
  11957. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11958. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11959. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11960. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11961. }
  11962. else
  11963. {
  11964. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11965. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11966. result = PASS;
  11967. }
  11968. sendResetConfirmation(uuid, comfirmstr);
  11969. return result;
  11970. }
  11971. int handleSendLocalListRequest(char *uuid, char *payload)
  11972. {
  11973. mtrace();
  11974. int result = FAIL;
  11975. char comfirmstr[20];
  11976. int checkState_Faulted = FALSE;
  11977. json_object *SendLocalList;
  11978. DEBUG_INFO("handleSendLocalListRequest...\n");
  11979. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11980. {
  11981. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11982. goto end;
  11983. }
  11984. //check Charge Point state
  11985. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11986. {
  11987. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11988. {
  11989. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11990. }
  11991. }
  11992. for (int index = 0; index < CCS_QUANTITY; index++)
  11993. {
  11994. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11995. {
  11996. checkState_Faulted = TRUE; //OCPP Status
  11997. }
  11998. }
  11999. for (int index = 0; index < GB_QUANTITY; index++)
  12000. {
  12001. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12002. {
  12003. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12004. }
  12005. }
  12006. //check Charge Point state
  12007. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12008. {
  12009. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12010. {
  12011. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12012. }
  12013. }
  12014. //check Charge Point state
  12015. for (int index = 0; index < AC_QUANTITY; index++)
  12016. {
  12017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12018. {
  12019. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12020. }
  12021. }
  12022. if(checkState_Faulted == TRUE)
  12023. {
  12024. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12025. goto end;
  12026. }
  12027. // Parsing payload
  12028. SendLocalList = json_tokener_parse(payload);
  12029. if(!is_error(SendLocalList))
  12030. {
  12031. // Required data
  12032. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12033. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12034. // Optional data
  12035. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12036. {
  12037. //Check UpdateType
  12038. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12039. {
  12040. //Local list full update
  12041. DEBUG_INFO("Local list full update.\n");
  12042. locallistVersion = 0;
  12043. OCPP_getListVerion();
  12044. /*if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  12045. {
  12046. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12047. goto end;
  12048. }*/
  12049. OCPP_cleanLocalList();
  12050. }
  12051. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12052. {
  12053. //Local list different update
  12054. DEBUG_INFO("Local list different update.\n");
  12055. locallistVersion = 0;
  12056. OCPP_getListVerion();
  12057. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  12058. {
  12059. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12060. goto end;
  12061. }
  12062. }
  12063. else
  12064. {
  12065. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12066. goto end;
  12067. }
  12068. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12069. {
  12070. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12071. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12072. goto end;
  12073. }
  12074. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12075. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12076. {
  12077. 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")));
  12078. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12079. {
  12080. 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")));
  12081. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12082. 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")));
  12083. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12084. 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")));
  12085. }
  12086. // Add to db
  12087. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12088. {
  12089. //Local list full update
  12090. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12091. idx,
  12092. ShmOCPP16DataPH->SendLocalList.ListVersion,
  12093. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12094. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12095. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12096. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12097. // update list
  12098. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  12099. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12100. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12101. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12102. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12103. }
  12104. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12105. {
  12106. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12107. idx,
  12108. ShmOCPP16DataPH->SendLocalList.ListVersion,
  12109. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12110. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12111. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12112. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12113. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  12114. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12115. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12116. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12117. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12118. }
  12119. }
  12120. }
  12121. else
  12122. {
  12123. //Check UpdateType
  12124. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12125. {
  12126. //Local list full update
  12127. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12128. OCPP_cleanLocalList();
  12129. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12130. goto end;
  12131. }
  12132. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12133. {
  12134. //Local list different update
  12135. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12136. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12137. goto end;
  12138. }
  12139. }
  12140. result = PASS;
  12141. }
  12142. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12143. end:
  12144. json_object_put(SendLocalList);
  12145. sendSendLocalListConfirmation(uuid, comfirmstr);
  12146. return result;
  12147. }
  12148. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12149. {
  12150. mtrace();
  12151. int result = FAIL;
  12152. struct StructSetChargingProfile SetProfileReq = {0};
  12153. int tempchargingProfileIdInt;
  12154. int tempstackLevelInt;
  12155. int chargingSchedulePeriodCount = 0;
  12156. char comfirmstr[20]={0};
  12157. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  12158. char rmFileCmd[128]={0};
  12159. int profileQuantity = 0;
  12160. int replaceableProfileCnt = 0;
  12161. json_object *SetChargingProfile;
  12162. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12163. SetChargingProfile = json_tokener_parse(payload);
  12164. if(!is_error(SetChargingProfile))
  12165. {
  12166. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12167. {
  12168. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12169. }
  12170. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12171. {
  12172. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12173. {
  12174. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12175. }
  12176. else
  12177. {
  12178. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12179. DEBUG_WARN("Cannot find chargingProfileId field.");
  12180. goto end;
  12181. }
  12182. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12183. {
  12184. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12185. }
  12186. else
  12187. {
  12188. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12189. DEBUG_WARN("Cannot find stackLevel field.");
  12190. goto end;
  12191. }
  12192. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12193. {
  12194. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12195. }
  12196. else
  12197. {
  12198. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12199. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12200. goto end;
  12201. }
  12202. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12203. {
  12204. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12205. }
  12206. else
  12207. {
  12208. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12209. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12210. goto end;
  12211. }
  12212. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12213. {
  12214. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12215. }
  12216. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12217. {
  12218. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12219. }
  12220. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12221. {
  12222. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12223. }
  12224. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12225. {
  12226. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12227. }
  12228. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12229. {
  12230. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12231. {
  12232. 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")));
  12233. }
  12234. else
  12235. {
  12236. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12237. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12238. goto end;
  12239. }
  12240. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12241. {
  12242. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12243. }
  12244. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12245. {
  12246. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12247. }
  12248. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12249. {
  12250. 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")));
  12251. }
  12252. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12253. {
  12254. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12255. if(chargingSchedulePeriodCount <= 10)
  12256. {
  12257. 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++)
  12258. {
  12259. 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)
  12260. {
  12261. 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"));
  12262. }
  12263. else
  12264. {
  12265. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12266. DEBUG_WARN("Cannot find startPeriod field.");
  12267. goto end;
  12268. }
  12269. 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)
  12270. {
  12271. 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"));
  12272. }
  12273. else
  12274. {
  12275. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12276. DEBUG_WARN("Cannot find limit field.");
  12277. goto end;
  12278. }
  12279. 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)
  12280. {
  12281. 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"));
  12282. }
  12283. }
  12284. }
  12285. }
  12286. else
  12287. {
  12288. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12289. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12290. goto end;
  12291. }
  12292. }
  12293. else
  12294. {
  12295. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12296. DEBUG_WARN("Cannot find chargingSchedule field.");
  12297. goto end;
  12298. }
  12299. }
  12300. }
  12301. // Profile periods quantity check
  12302. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12303. {
  12304. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12305. goto end;
  12306. }
  12307. // Check invalid limit
  12308. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12309. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12310. {
  12311. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12312. {
  12313. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12314. {
  12315. 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)))) ||
  12316. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12317. {
  12318. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12319. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12320. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12321. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12322. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12323. goto end;
  12324. }
  12325. }
  12326. }
  12327. else
  12328. {
  12329. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12330. {
  12331. 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) ||
  12332. (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)))
  12333. {
  12334. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12335. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12336. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12337. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12338. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12339. goto end;
  12340. }
  12341. }
  12342. }
  12343. }
  12344. // Profile purpose info check
  12345. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12346. {
  12347. FILE *fp;
  12348. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12349. if(SetProfileReq.ConnectorId != 0)
  12350. {
  12351. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12352. goto end;
  12353. }
  12354. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12355. if (!fp)
  12356. {
  12357. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12358. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12359. }
  12360. else
  12361. {
  12362. char *line = NULL;
  12363. size_t len = 0;
  12364. while(getline(&line, &len, fp) != -1)
  12365. {
  12366. json_object *obj = NULL;
  12367. obj = json_tokener_parse(line);
  12368. if(is_error(obj))
  12369. {
  12370. DEBUG_ERROR("Parse txProfile from file error.\n");
  12371. }
  12372. else
  12373. {
  12374. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12375. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12376. {
  12377. profileQuantity += 1;
  12378. }
  12379. else
  12380. replaceableProfileCnt += 1;
  12381. }
  12382. }
  12383. }
  12384. fclose(fp);
  12385. }
  12386. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12387. {
  12388. FILE *fp;
  12389. char filename[128]={0};
  12390. int tmpProfileQuantity;
  12391. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12392. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12393. {
  12394. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12395. goto end;
  12396. }
  12397. if(SetProfileReq.ConnectorId == 0)
  12398. {
  12399. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12400. {
  12401. tmpProfileQuantity = 0;
  12402. memset(filename, 0, ARRAY_SIZE(filename));
  12403. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12404. fp = fopen(filename, "r");
  12405. if (!fp)
  12406. {
  12407. DEBUG_INFO("%s does not create.\n", filename);
  12408. fp = fopen(filename, "w+");
  12409. }
  12410. else
  12411. {
  12412. char *line = NULL;
  12413. size_t len = 0;
  12414. while(getline(&line, &len, fp) != -1)
  12415. {
  12416. json_object *obj = NULL;
  12417. obj = json_tokener_parse(line);
  12418. if(is_error(obj))
  12419. {
  12420. DEBUG_ERROR("Parse txProfile from file error.\n");
  12421. }
  12422. else
  12423. {
  12424. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12425. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12426. {
  12427. tmpProfileQuantity += 1;
  12428. }
  12429. else
  12430. replaceableProfileCnt += 1;
  12431. }
  12432. }
  12433. }
  12434. fclose(fp);
  12435. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12436. }
  12437. }
  12438. else
  12439. {
  12440. memset(filename, 0, ARRAY_SIZE(filename));
  12441. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12442. fp = fopen(filename, "r");
  12443. if (!fp)
  12444. {
  12445. DEBUG_INFO("%s does not create.\n", filename);
  12446. fp = fopen(filename, "w+");
  12447. }
  12448. else
  12449. {
  12450. char *line = NULL;
  12451. size_t len = 0;
  12452. while(getline(&line, &len, fp) != -1)
  12453. {
  12454. json_object *obj = NULL;
  12455. obj = json_tokener_parse(line);
  12456. if(is_error(obj))
  12457. {
  12458. DEBUG_ERROR("Parse txProfile from file error.\n");
  12459. }
  12460. else
  12461. {
  12462. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12463. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12464. {
  12465. profileQuantity += 1;
  12466. }
  12467. else
  12468. replaceableProfileCnt += 1;
  12469. }
  12470. }
  12471. }
  12472. fclose(fp);
  12473. }
  12474. }
  12475. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12476. {
  12477. int isMatchTransactiodId= FALSE;
  12478. FILE *fp;
  12479. char filename[128]={0};
  12480. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12481. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12482. if(SetProfileReq.ConnectorId == 0)
  12483. {
  12484. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12485. goto end;
  12486. }
  12487. int tempIndex = 0;
  12488. //check Transaction active
  12489. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12490. {
  12491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12492. {
  12493. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12494. }
  12495. else
  12496. {
  12497. tempIndex = SetProfileReq.ConnectorId -1;
  12498. }
  12499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12500. {
  12501. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12502. {
  12503. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12504. {
  12505. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12506. {
  12507. isMatchTransactiodId = TRUE;
  12508. break;
  12509. }
  12510. }
  12511. }
  12512. }
  12513. }
  12514. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12515. {
  12516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12517. {
  12518. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12519. }
  12520. else
  12521. {
  12522. tempIndex = SetProfileReq.ConnectorId -1;
  12523. }
  12524. for (int index = 0; index < CCS_QUANTITY; index++)
  12525. {
  12526. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12527. {
  12528. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12529. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12530. {
  12531. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12532. {
  12533. isMatchTransactiodId = TRUE;
  12534. break;
  12535. }
  12536. }
  12537. }
  12538. }
  12539. }
  12540. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12541. {
  12542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12543. {
  12544. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12545. }
  12546. else
  12547. {
  12548. tempIndex = SetProfileReq.ConnectorId -1;
  12549. }
  12550. for (int index = 0; index < GB_QUANTITY; index++)
  12551. {
  12552. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12553. {
  12554. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12555. {
  12556. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12557. {
  12558. isMatchTransactiodId = TRUE;
  12559. break;
  12560. }
  12561. }
  12562. }
  12563. }
  12564. }
  12565. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12566. {
  12567. tempIndex = SetProfileReq.ConnectorId -1;
  12568. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12569. {
  12570. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12571. {
  12572. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12573. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12574. {
  12575. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12576. {
  12577. isMatchTransactiodId = TRUE;
  12578. break;
  12579. }
  12580. }
  12581. }
  12582. }
  12583. }
  12584. else
  12585. {
  12586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12587. {
  12588. tempIndex = 2;
  12589. }
  12590. else
  12591. {
  12592. tempIndex = (SetProfileReq.ConnectorId -1);
  12593. }
  12594. for (int index = 0; index < AC_QUANTITY; index++)
  12595. {
  12596. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12597. {
  12598. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12599. {
  12600. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12601. {
  12602. isMatchTransactiodId = TRUE;
  12603. break;
  12604. }
  12605. }
  12606. }
  12607. }
  12608. }
  12609. //check Transaction active
  12610. if(isMatchTransactiodId == FALSE)
  12611. {
  12612. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12613. goto end;
  12614. }
  12615. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12616. {
  12617. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12618. goto end;
  12619. }
  12620. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12621. fp = fopen(filename, "r");
  12622. if (!fp)
  12623. {
  12624. DEBUG_INFO("%s does not create.\n", filename);
  12625. fp = fopen(filename, "w+");
  12626. }
  12627. else
  12628. {
  12629. char *line = NULL;
  12630. size_t len = 0;
  12631. while(getline(&line, &len, fp) != -1)
  12632. {
  12633. json_object *obj = NULL;
  12634. obj = json_tokener_parse(line);
  12635. if(is_error(obj))
  12636. {
  12637. DEBUG_ERROR("Parse txProfile from file error.\n");
  12638. }
  12639. else
  12640. {
  12641. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12642. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12643. {
  12644. profileQuantity += 1;
  12645. }
  12646. else
  12647. replaceableProfileCnt += 1;
  12648. }
  12649. }
  12650. }
  12651. fclose(fp);
  12652. }
  12653. // Check ChargeProfileMaxStackLevel
  12654. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12655. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12656. {
  12657. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12658. goto end;
  12659. }
  12660. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12661. {
  12662. FILE *fp;
  12663. char dataLine[4096]={0};
  12664. char fnametemp[128]={0};
  12665. int tmpProfileQuantity;
  12666. //Check ChargePointMaxProfile.json exit
  12667. profileQuantity = 0;
  12668. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12669. {
  12670. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12671. //Check Charging Profile Count
  12672. tmpProfileQuantity = 0;
  12673. while(fscanf(fp, "%s", dataLine) != EOF)
  12674. {
  12675. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12676. {
  12677. profileQuantity += 1;
  12678. tmpProfileQuantity += 1;
  12679. }
  12680. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12681. }
  12682. fclose(fp);
  12683. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12684. }
  12685. //Check TxDefaultProfile_%d.json
  12686. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12687. {
  12688. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12689. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12690. if((access(fnametemp,F_OK))!=-1)
  12691. {
  12692. fp = fopen(fnametemp, "r");
  12693. //Check Charging Profile Count
  12694. tmpProfileQuantity = 0;
  12695. while(fscanf(fp, "%s", dataLine) != EOF)
  12696. {
  12697. //DEBUG_INFO("word=%s\n",word);
  12698. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12699. {
  12700. profileQuantity += 1;
  12701. tmpProfileQuantity += 1;
  12702. }
  12703. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12704. }
  12705. fclose(fp);
  12706. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12707. }
  12708. }
  12709. //Check TxProfile_%d.json
  12710. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12711. {
  12712. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12713. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12714. if((access(fnametemp,F_OK))!=-1)
  12715. {
  12716. fp = fopen(fnametemp, "r");
  12717. //Check Charging Profile Count
  12718. tmpProfileQuantity = 0;
  12719. while(fscanf(fp, "%s", dataLine) != EOF)
  12720. {
  12721. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12722. {
  12723. profileQuantity += 1;
  12724. tmpProfileQuantity += 1;
  12725. }
  12726. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12727. }
  12728. fclose(fp);
  12729. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12730. }
  12731. }
  12732. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12733. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12734. // To check total Profile quantity
  12735. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12736. {
  12737. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12738. {
  12739. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12740. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12741. goto end;
  12742. }
  12743. }
  12744. else
  12745. {
  12746. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12747. {
  12748. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12749. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12750. goto end;
  12751. }
  12752. }
  12753. }
  12754. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12755. //**********************************Write to File********************************************************/
  12756. {
  12757. FILE *infile;
  12758. FILE *outfile;
  12759. char dataLine[4096]={0};
  12760. char filename[128]={0};
  12761. int chkChar=0;
  12762. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12763. {
  12764. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12765. {
  12766. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12767. }
  12768. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12769. {
  12770. if(SetProfileReq.ConnectorId==0)
  12771. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12772. else
  12773. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12774. }
  12775. else
  12776. {
  12777. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12778. }
  12779. infile = fopen (filename, "r");
  12780. outfile = fopen (tempfile, "w");
  12781. chkChar = fgetc(infile);
  12782. rewind(infile);
  12783. if(chkChar == EOF)
  12784. {
  12785. // Profile is empty
  12786. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12787. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12788. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12789. fclose(infile);
  12790. fclose(outfile);
  12791. sprintf(rmFileCmd,"rm -f %s",filename);
  12792. system(rmFileCmd);
  12793. rename(tempfile, filename);
  12794. }
  12795. else
  12796. {
  12797. // Profile is not empty
  12798. int ChargingProfileAdded = FALSE;
  12799. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12800. {
  12801. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12802. json_object *tmpChargingProfile;
  12803. tmpChargingProfile = json_tokener_parse(dataLine);
  12804. if(!is_error(SetChargingProfile))
  12805. {
  12806. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12807. {
  12808. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12809. {
  12810. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12811. }
  12812. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12813. {
  12814. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12815. }
  12816. }
  12817. }
  12818. json_object_put(tmpChargingProfile);
  12819. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12820. {
  12821. if(ChargingProfileAdded == FALSE)
  12822. {
  12823. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12824. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12825. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12826. ChargingProfileAdded = TRUE;
  12827. }
  12828. }
  12829. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12830. {
  12831. if(ChargingProfileAdded == FALSE)
  12832. {
  12833. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12834. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12835. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12836. ChargingProfileAdded = TRUE;
  12837. }
  12838. }
  12839. else
  12840. {
  12841. fprintf(outfile,"%s\n",dataLine);
  12842. if(ChargingProfileAdded == FALSE)
  12843. {
  12844. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12845. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12846. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12847. ChargingProfileAdded = TRUE;
  12848. }
  12849. }
  12850. } // end of while loop
  12851. fclose(infile);
  12852. fclose(outfile);
  12853. sprintf(rmFileCmd,"rm -f %s",filename);
  12854. system(rmFileCmd);
  12855. rename(tempfile, filename);
  12856. }
  12857. }
  12858. sleep(1);
  12859. result = TRUE;
  12860. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12861. }
  12862. end:
  12863. json_object_put(SetChargingProfile);
  12864. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12865. {
  12866. if(SetProfileReq.ConnectorId == 0)
  12867. {
  12868. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12869. {
  12870. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12871. }
  12872. }
  12873. else
  12874. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12875. }
  12876. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12877. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12878. return result;
  12879. }
  12880. int handleTriggerMessageRequest(char *uuid, char *payload)
  12881. {
  12882. mtrace();
  12883. int result = FAIL;
  12884. int connectorIdIsNULL = FALSE;
  12885. int connectorIdInt =0;
  12886. char sstr[40]={0},sstrtemp[100]={ 0 };
  12887. char requestedMessagestr[40]={0};
  12888. char comfirmstr[20]={0};
  12889. int c = 0;
  12890. char *loc;
  12891. DEBUG_INFO("handleTriggerMessageRequest\n");
  12892. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12893. strcpy(sstrtemp, stringtrimspace(payload));
  12894. c = 0;
  12895. loc = strstr(sstrtemp, "requestedMessage");
  12896. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12897. {
  12898. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12899. c++;
  12900. }
  12901. sstr[c] = '\0';
  12902. strcpy(requestedMessagestr, sstr);
  12903. c = 0;
  12904. loc = strstr(sstrtemp, "connectorId");
  12905. if(loc == NULL)
  12906. {
  12907. connectorIdIsNULL = TRUE;
  12908. }
  12909. else
  12910. {
  12911. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12912. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12913. {
  12914. sstr[c] = loc[strlen("connectorId")+2+c];
  12915. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12916. c++;
  12917. }
  12918. sstr[c] = '\0';
  12919. connectorIdInt = atoi(sstr);
  12920. }
  12921. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12922. {
  12923. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12924. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12925. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12926. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12927. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12928. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12929. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12930. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12931. {
  12932. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12933. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12934. return TRUE;
  12935. }
  12936. else
  12937. {
  12938. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12939. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12940. }
  12941. }
  12942. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12943. {
  12944. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12945. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12946. return TRUE;
  12947. }
  12948. //==========================
  12949. // Trigger message
  12950. //==========================
  12951. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12952. {
  12953. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12954. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12955. {
  12956. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12957. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12958. }
  12959. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12960. }
  12961. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12962. {
  12963. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12964. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12965. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12966. }
  12967. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12968. {
  12969. //sendBootNotificationRequest();
  12970. server_sign = FALSE;
  12971. }
  12972. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12973. {
  12974. refreshStartTimer(&clientTime.Heartbeat);
  12975. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12976. }
  12977. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12978. {
  12979. if(connectorIdIsNULL == FALSE)
  12980. {
  12981. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12982. {
  12983. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12984. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12985. }
  12986. }
  12987. else
  12988. {
  12989. for(int idx=0;idx< gunTotalNumber;idx++)
  12990. {
  12991. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12992. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12993. }
  12994. }
  12995. }
  12996. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12997. {
  12998. if(connectorIdIsNULL == FALSE)
  12999. {
  13000. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13001. {
  13002. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13003. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  13004. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13005. }
  13006. }
  13007. else
  13008. {
  13009. for(int idx=0;idx< gunTotalNumber;idx++)
  13010. {
  13011. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  13012. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13013. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13014. }
  13015. }
  13016. }
  13017. return result;
  13018. }
  13019. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13020. {
  13021. mtrace();
  13022. int result = FAIL;
  13023. int connectorIdInt =0;
  13024. char comfirmstr[20]={0};
  13025. int tempIndex = 0;
  13026. json_object *UnlockConnector;
  13027. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13028. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13029. UnlockConnector = json_tokener_parse(payload);
  13030. if(!is_error(UnlockConnector))
  13031. {
  13032. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13033. {
  13034. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13035. }
  13036. }
  13037. json_object_put(UnlockConnector);
  13038. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13039. if(gunTotalNumber == 0)
  13040. {
  13041. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13042. goto end;
  13043. }
  13044. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13045. {
  13046. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13047. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13048. goto end;
  13049. }
  13050. else
  13051. {
  13052. //check Transaction active
  13053. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13054. {
  13055. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13056. {
  13057. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13058. }
  13059. else
  13060. {
  13061. tempIndex = connectorIdInt -1;
  13062. }
  13063. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13064. {
  13065. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13066. {
  13067. //stop Transaction
  13068. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13069. }
  13070. }
  13071. }
  13072. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13073. {
  13074. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13075. {
  13076. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13077. }
  13078. else
  13079. {
  13080. tempIndex = connectorIdInt -1;
  13081. }
  13082. for (int index = 0; index < CCS_QUANTITY; index++)
  13083. {
  13084. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13085. {
  13086. //stop Transaction
  13087. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13088. }
  13089. }
  13090. }
  13091. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13092. {
  13093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13094. {
  13095. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13096. }
  13097. else
  13098. {
  13099. tempIndex = connectorIdInt -1;
  13100. }
  13101. for (int index = 0; index < GB_QUANTITY; index++)
  13102. {
  13103. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13104. {
  13105. //stop Transaction
  13106. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13107. }
  13108. }
  13109. }
  13110. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13111. {
  13112. tempIndex = connectorIdInt -1;
  13113. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13114. {
  13115. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13116. {
  13117. //stop Transaction
  13118. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13119. }
  13120. }
  13121. }
  13122. else
  13123. {
  13124. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13125. {
  13126. tempIndex = 2;
  13127. }
  13128. else
  13129. {
  13130. tempIndex = connectorIdInt-1;
  13131. }
  13132. for (int index = 0; index < AC_QUANTITY; index++)
  13133. {
  13134. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13135. {
  13136. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13137. }
  13138. }
  13139. }
  13140. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13141. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  13142. result = TRUE;
  13143. return result;
  13144. }
  13145. end:
  13146. //json_object_put(obj); --- remove temporally
  13147. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13148. return result;
  13149. }
  13150. static char UpdateFirmwarepayloadData[300]={0};
  13151. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13152. {
  13153. mtrace();
  13154. int result = FAIL;
  13155. pthread_t t;
  13156. sendUpdateFirmwareConfirmation(uuid);
  13157. memset(UpdateFirmwarepayloadData, 0, 300);
  13158. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13159. if(!interLock.isUpdateFirmwareGoing)
  13160. {
  13161. interLock.isUpdateFirmwareGoing = 1;
  13162. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13163. sleep(1);
  13164. }
  13165. else
  13166. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13167. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  13168. return result;
  13169. }
  13170. void *UpdateFirmwareProcess(void *data)
  13171. {
  13172. pthread_detach(pthread_self());
  13173. mtrace();
  13174. int retriesInt =0, retryIntervalInt=0;
  13175. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  13176. int port=0;
  13177. char locationstr[512]={0}, retrieveDatestr[36]={0};
  13178. int isSuccess = 0;
  13179. char ftpbuf[512];
  13180. char temp[100];
  13181. char * pch;
  13182. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13183. json_object *UpdateFirmware;
  13184. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13185. if(!is_error(UpdateFirmware))
  13186. {
  13187. // Required data
  13188. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13189. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13190. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13191. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13192. // Optional data
  13193. if(json_object_object_get(UpdateFirmware, "retries"))
  13194. {
  13195. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13196. }
  13197. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13198. {
  13199. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13200. }
  13201. }
  13202. json_object_put(UpdateFirmware);
  13203. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13204. memset(path, 0, ARRAY_SIZE(path));
  13205. // Wait retrieveData
  13206. if(strlen(retrieveDatestr) > 10)
  13207. {
  13208. do
  13209. {
  13210. sleep(1);
  13211. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13212. }
  13213. // Ready to download
  13214. system("rm -f /mnt/*");
  13215. if(strncmp(locationstr,"http", 4) == 0)
  13216. {
  13217. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13218. sprintf(ftppath,"/%s", path);
  13219. DEBUG_INFO("locationstr: %s\n", locationstr);
  13220. DEBUG_INFO("protocol: %s\n",protocol);
  13221. DEBUG_INFO("host: %s\n",host);
  13222. DEBUG_INFO("path: %s\n",path);
  13223. DEBUG_INFO("ftppath: %s\n",ftppath);
  13224. int ftppathlen=strlen(ftppath);
  13225. int i=1;
  13226. char filenametemp[50];
  13227. while(i < ftppathlen)
  13228. {
  13229. int len=ftppathlen-i;
  13230. if(ftppath[len]== 47) // '/' ascll code: 47
  13231. {
  13232. DEBUG_INFO("compare '/' all right\n");
  13233. break;
  13234. }
  13235. i=i+1;
  13236. }
  13237. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13238. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13239. filenametemp[i+1] = 0;
  13240. do
  13241. {
  13242. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13243. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13244. sleep(1);
  13245. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13246. if(!isSuccess)
  13247. {
  13248. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13249. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13250. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13251. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13252. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13253. }
  13254. else
  13255. {
  13256. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13257. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13258. }
  13259. retriesInt--;
  13260. }while((isSuccess == 0)&&(retriesInt >= 0));
  13261. }
  13262. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13263. {
  13264. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13265. memset(temp, 0, ARRAY_SIZE(temp));
  13266. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13267. strcpy(ftpbuf, locationstr);
  13268. int ftppathlen=strlen(ftpbuf);
  13269. int i=1;
  13270. char filenametemp[50];
  13271. while(i < ftppathlen)
  13272. {
  13273. int len=ftppathlen-i;
  13274. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13275. {
  13276. DEBUG_INFO(" compare '/' all right\n");
  13277. break;
  13278. }
  13279. i=i+1;
  13280. }
  13281. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13282. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13283. filenametemp[i+1] = 0;
  13284. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13285. pch=strchr(temp,'@');
  13286. if(pch==NULL)
  13287. {
  13288. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13289. protocol, host, &port, path);
  13290. strcpy(user,"anonymous");
  13291. strcpy(password,"");
  13292. }
  13293. else
  13294. {
  13295. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13296. protocol, user, host, &port, path);
  13297. }
  13298. sscanf(host,"%[^/]%s",host1, path1);
  13299. sprintf(ftppath,"%s:/%s", host,path);
  13300. if(port == 0)
  13301. {
  13302. port = 21;
  13303. }
  13304. do
  13305. {
  13306. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13307. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13308. sleep(1);
  13309. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13310. if(!isSuccess)
  13311. {
  13312. //BulldogUtil.sleepMs(interval*1000);
  13313. DEBUG_INFO("Update firmware request and download file fail.\n");
  13314. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13315. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13316. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13317. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13318. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13319. }
  13320. else
  13321. {
  13322. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13323. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13324. }
  13325. retriesInt--;
  13326. }while((!isSuccess)&&(retriesInt >= 0));
  13327. }
  13328. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13329. {
  13330. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13331. memset(temp, 0, ARRAY_SIZE(temp));
  13332. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13333. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13334. int ftppathlen=strlen(ftpbuf);
  13335. int i=1;
  13336. char filenametemp[50];
  13337. while(i < ftppathlen)
  13338. {
  13339. int len=ftppathlen-i;
  13340. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13341. {
  13342. DEBUG_INFO(" compare '/' all right\n");
  13343. break;
  13344. }
  13345. i=i+1;
  13346. }
  13347. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13348. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13349. filenametemp[i+1] = 0;
  13350. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13351. pch=strchr(temp,'@');
  13352. if(pch==NULL)
  13353. {
  13354. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13355. protocol, host, &port, path);
  13356. strcpy(user,"anonymous");
  13357. strcpy(password,"");
  13358. }
  13359. else
  13360. {
  13361. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13362. protocol, user, password, host, &port, path);
  13363. }
  13364. sscanf(host,"%[^/]%s",host1, path1);
  13365. sprintf(ftppath,"%s", path1);
  13366. //DEBUG_INFO("protocol =%s\n",protocol);
  13367. //DEBUG_INFO("user =%s\n",user);
  13368. //DEBUG_INFO("password =%s\n",password);
  13369. //DEBUG_INFO("host1 =%s\n",host1);
  13370. //DEBUG_INFO("port =%d\n",port);
  13371. //DEBUG_INFO("path1 =%s\n",path1);
  13372. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13373. //ftpFile(host, user, password, port, ftppath, fname);
  13374. //download firmware pthred
  13375. if(port == 0)
  13376. {
  13377. port = 21;
  13378. }
  13379. do
  13380. {
  13381. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13382. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13383. sleep(1);
  13384. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13385. if(!isSuccess)
  13386. {
  13387. //BulldogUtil.sleepMs(interval*1000);
  13388. DEBUG_INFO("Update firmware request and download file fail.\n");
  13389. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13390. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13391. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13392. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13393. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13394. }
  13395. else
  13396. {
  13397. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13398. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13399. }
  13400. retriesInt--;
  13401. }while((!isSuccess)&&(retriesInt >= 0));
  13402. }
  13403. else
  13404. {
  13405. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13406. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13407. sleep(1);
  13408. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13409. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13410. }
  13411. // OCPPPH only, must announce CSU upgrade firmware
  13412. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13413. interLock.isUpdateFirmwareGoing = 0;
  13414. pthread_exit(NULL);
  13415. }
  13416. int handleCertificateSignedRequest(char *uuid, char *payload)
  13417. {
  13418. mtrace();
  13419. int result = PASS;
  13420. json_object *CertificateSigned;
  13421. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13422. CertificateSigned = json_tokener_parse(payload);
  13423. if(!is_error(CertificateSigned))
  13424. {
  13425. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13426. }
  13427. json_object_put(CertificateSigned);
  13428. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  13429. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  13430. fclose(fp);
  13431. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13432. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  13433. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  13434. sendCertificateSignedConfirmation(uuid);
  13435. return result;
  13436. }
  13437. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13438. {
  13439. mtrace();
  13440. int result = PASS;
  13441. json_object *DeleteCertificate;
  13442. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13443. DeleteCertificate = json_tokener_parse(payload);
  13444. if(!is_error(DeleteCertificate))
  13445. {
  13446. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13447. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13448. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13449. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13450. }
  13451. json_object_put(DeleteCertificate);
  13452. /*
  13453. * TODO: Delete certificateSigned process
  13454. */
  13455. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  13456. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  13457. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  13458. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  13459. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  13460. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  13461. sendDeleteCertificateConfirmation(uuid);
  13462. return result;
  13463. }
  13464. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13465. {
  13466. mtrace();
  13467. int result = PASS;
  13468. json_object *ExtendedTriggerMessage;
  13469. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13470. ExtendedTriggerMessage = json_tokener_parse(payload);
  13471. if(!is_error(ExtendedTriggerMessage))
  13472. {
  13473. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13474. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13475. {
  13476. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13477. }
  13478. else
  13479. {
  13480. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13481. }
  13482. }
  13483. json_object_put(ExtendedTriggerMessage);
  13484. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13485. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13486. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13487. {
  13488. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13489. }
  13490. else
  13491. {
  13492. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13493. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13494. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13495. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13496. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13497. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13498. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13499. {
  13500. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13501. }
  13502. else
  13503. {
  13504. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13505. }
  13506. }
  13507. sendExtendedTriggerMessageConfirmation(uuid);
  13508. //==========================
  13509. // Trigger message
  13510. //==========================
  13511. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13512. {
  13513. //sendBootNotificationRequest();
  13514. server_sign = FALSE;
  13515. }
  13516. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13517. {
  13518. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13519. }
  13520. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13521. {
  13522. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13523. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13524. {
  13525. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13526. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13527. }
  13528. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13529. }
  13530. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13531. {
  13532. refreshStartTimer(&clientTime.Heartbeat);
  13533. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13534. }
  13535. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13536. {
  13537. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13538. {
  13539. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13540. }
  13541. else
  13542. {
  13543. for(int idx=0;idx< gunTotalNumber;idx++)
  13544. {
  13545. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13546. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13547. }
  13548. }
  13549. }
  13550. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13551. {
  13552. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13553. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13554. {
  13555. 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\" &");
  13556. }
  13557. }
  13558. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13559. {
  13560. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13561. {
  13562. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13563. }
  13564. else
  13565. {
  13566. for(int idx=0;idx< gunTotalNumber;idx++)
  13567. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13568. }
  13569. }
  13570. return result;
  13571. }
  13572. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13573. {
  13574. mtrace();
  13575. int result = PASS;
  13576. json_object *GetInstalledCertificateIds;
  13577. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13578. GetInstalledCertificateIds = json_tokener_parse(payload);
  13579. if(!is_error(GetInstalledCertificateIds))
  13580. {
  13581. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13582. }
  13583. json_object_put(GetInstalledCertificateIds);
  13584. /*
  13585. * TODO: Return installed certificate process
  13586. */
  13587. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13588. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13589. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13590. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13591. sendGetInstalledCertificateIdsConfirmation(uuid);
  13592. return result;
  13593. }
  13594. int handleGetLogRequest(char *uuid, char *payload)
  13595. {
  13596. mtrace();
  13597. int result = PASS;
  13598. json_object *GetLog;
  13599. DEBUG_INFO("handleGetLogRequest...\n");
  13600. GetLog = json_tokener_parse(payload);
  13601. if(!is_error(GetLog))
  13602. {
  13603. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13604. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13605. if(json_object_object_get(GetLog, "retries") != NULL)
  13606. {
  13607. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13608. }
  13609. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13610. {
  13611. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13612. }
  13613. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13614. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13615. {
  13616. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13617. }
  13618. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13619. {
  13620. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13621. }
  13622. }
  13623. json_object_put(GetLog);
  13624. /*
  13625. * TODO: Upload log process
  13626. */
  13627. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13628. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13629. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13630. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13631. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13632. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13633. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13634. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13635. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13636. sendGetLogConfirmation(uuid);
  13637. return result;
  13638. }
  13639. int handleInstallCertificateRequest(char *uuid, char *payload)
  13640. {
  13641. mtrace();
  13642. int result = PASS;
  13643. json_object *InstallCertificate;
  13644. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13645. InstallCertificate = json_tokener_parse(payload);
  13646. if(!is_error(InstallCertificate))
  13647. {
  13648. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13649. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13650. /*
  13651. * TODO: Install certificate process
  13652. */
  13653. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13654. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13655. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13656. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13657. sendInstallCertificateConfirmation(uuid);
  13658. }
  13659. json_object_put(InstallCertificate);
  13660. return result;
  13661. }
  13662. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13663. {
  13664. mtrace();
  13665. int result = PASS;
  13666. json_object *SignedUpdateFirmware;
  13667. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13668. SignedUpdateFirmware = json_tokener_parse(payload);
  13669. if(!is_error(SignedUpdateFirmware))
  13670. {
  13671. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13672. {
  13673. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13674. }
  13675. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13676. {
  13677. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13678. }
  13679. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13680. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13681. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13682. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13683. {
  13684. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13685. }
  13686. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13687. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13688. }
  13689. json_object_put(SignedUpdateFirmware);
  13690. /*
  13691. * TODO: Upgrade firmware process
  13692. */
  13693. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13694. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13695. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13696. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13697. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13698. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13699. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13700. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13701. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13702. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13703. sendInstallCertificateConfirmation(uuid);
  13704. return result;
  13705. }
  13706. int handleUnknownRequest(char *uuid, char *payload)
  13707. {
  13708. mtrace();
  13709. int result = PASS;
  13710. DEBUG_INFO("handleUnknownRequest...\n");
  13711. sendUnknownConfirmation(uuid);
  13712. result = PASS;
  13713. return result;
  13714. }
  13715. //==========================================
  13716. // Handle server response routine
  13717. //==========================================
  13718. void handleAuthorizeResponse(char *payload, int gun_index)
  13719. {
  13720. mtrace();
  13721. char expiryDatestr[36]={0};
  13722. char parentIdTagstr[21]={0};
  13723. char statusstr[20]={0};
  13724. int expiryDateISNULL=FALSE;
  13725. int parentIdTagISNULL=FALSE;
  13726. DEBUG_INFO("handleAuthorizeResponse...\n");
  13727. json_object *Authorize;
  13728. Authorize = json_tokener_parse(payload);
  13729. if(!is_error(Authorize))
  13730. {
  13731. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13732. {
  13733. // Required data
  13734. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13735. // Optional data
  13736. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13737. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13738. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13739. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13740. }
  13741. }
  13742. json_object_put(Authorize);
  13743. if(expiryDateISNULL == FALSE)
  13744. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13745. if(parentIdTagISNULL == FALSE)
  13746. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13747. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13748. //Update idTag information to authorization cache if supproted
  13749. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13750. {
  13751. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13752. }
  13753. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13754. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13755. authorizeRetryTimes = 0;
  13756. }
  13757. void handleBootNotificationResponse(char *payload, int gun_index)
  13758. {
  13759. mtrace();
  13760. char statusStr[12]={0};
  13761. char currentTimeStr[30]={0};
  13762. int intervalInt = 0;
  13763. DEBUG_INFO("handleBootNotificationResponse...\n");
  13764. json_object *BootNotification;
  13765. BootNotification = json_tokener_parse(payload);
  13766. if(!is_error(BootNotification))
  13767. {
  13768. // Required data
  13769. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13770. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13771. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13772. }
  13773. json_object_put(BootNotification);
  13774. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13775. BootNotificationInterval = intervalInt;
  13776. //write back to ShmOCPP16DataPH->BootNotification
  13777. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13778. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13779. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13780. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13781. {
  13782. BootNotificationInterval = 0;
  13783. if((intervalInt == 0) || (intervalInt >= 10))
  13784. {
  13785. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13786. HeartBeatWaitTime = intervalInt;
  13787. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13788. }
  13789. server_sign = TRUE;
  13790. server_pending =FALSE;
  13791. }
  13792. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13793. {
  13794. server_pending = TRUE;
  13795. }
  13796. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13797. srand(time(NULL));
  13798. refreshStartTimer(&clientTime.Heartbeat);
  13799. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13800. SetOcppConnStatus(TRUE);
  13801. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13802. }
  13803. void handleDataTransferResponse(char *payload, int gun_index)
  13804. {
  13805. json_object *DataTransfer = json_tokener_parse(payload);
  13806. if(!is_error(DataTransfer))
  13807. {
  13808. // Required data
  13809. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13810. // Optional data
  13811. if(json_object_object_get(DataTransfer, "data") != NULL)
  13812. {
  13813. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13814. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13815. if(!is_error(Data))
  13816. {
  13817. if(json_object_object_get(Data, "msgId") != NULL)
  13818. {
  13819. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13820. {
  13821. 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")));
  13822. }
  13823. }
  13824. }
  13825. json_object_put(Data);
  13826. }
  13827. }
  13828. json_object_put(DataTransfer);
  13829. }
  13830. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13831. {
  13832. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13833. //struct json_object *obj;
  13834. // obj = json_tokener_parse(payload);
  13835. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13836. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13837. //No fields are defined.
  13838. }
  13839. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13840. {
  13841. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13842. //struct json_object *obj;
  13843. // obj = json_tokener_parse(payload);
  13844. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13845. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13846. //No fields are defined.
  13847. }
  13848. void handleHeartbeatResponse(char *payload, int gun_index)
  13849. {
  13850. mtrace();
  13851. DEBUG_INFO("handleHeartbeatResponse...\n");
  13852. json_object *Heartbeat;
  13853. Heartbeat = json_tokener_parse(payload);
  13854. if(!is_error(Heartbeat))
  13855. {
  13856. // Required data
  13857. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13858. }
  13859. json_object_put(Heartbeat);
  13860. if(FirstHeartBeat == 0)
  13861. {
  13862. FirstHeartBeat = 1;
  13863. DEBUG_INFO("FirstHeartBeat \n");
  13864. }
  13865. HeartBeatWithNOResponse = 0;
  13866. refreshStartTimer(&clientTime.Heartbeat);
  13867. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13868. }
  13869. void handleMeterValuesResponse(char *payload, int gun_index)
  13870. {
  13871. mtrace();
  13872. DEBUG_INFO("handleMeterValuesResponse...\n");
  13873. isQueueSendable = 1;
  13874. }
  13875. void handleStartTransactionResponse(char *payload, int gun_index)
  13876. {
  13877. mtrace();
  13878. //int transactionIdInt = 0;
  13879. FILE *outfile;
  13880. char data[100]={0};
  13881. DEBUG_INFO("handleStartTransactionResponse...\n");
  13882. json_object *StartTransaction;
  13883. StartTransaction = json_tokener_parse(payload);
  13884. if(!is_error(StartTransaction))
  13885. {
  13886. // Required data
  13887. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13888. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13889. // Optional data
  13890. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13891. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13892. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13893. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13894. }
  13895. json_object_put(StartTransaction);
  13896. isQueueSendable = 1;
  13897. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13898. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13899. //-----------Start : write to the Queue TransactionId file -----------------//
  13900. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13901. {}
  13902. else
  13903. {
  13904. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13905. if(log == NULL)
  13906. {
  13907. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13908. return ;
  13909. }
  13910. else
  13911. {
  13912. fclose(log);
  13913. }
  13914. }
  13915. // open file for writing
  13916. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13917. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13918. {
  13919. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13920. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13921. fputs(data, outfile);
  13922. fclose (outfile);
  13923. }
  13924. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13925. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13926. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13927. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13928. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13929. }
  13930. void handleStatusNotificationResponse(char *payload, int gun_index)
  13931. {
  13932. mtrace();
  13933. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13934. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13935. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13936. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13937. }
  13938. void handleStopTransactionnResponse(char *payload, int gun_index)
  13939. {
  13940. mtrace();
  13941. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13942. json_object *StopTransaction;
  13943. StopTransaction = json_tokener_parse(payload);
  13944. if(!is_error(StopTransaction))
  13945. {
  13946. // Optional data
  13947. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13948. {
  13949. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13950. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13951. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13952. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13953. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13954. }
  13955. }
  13956. json_object_put(StopTransaction);
  13957. isQueueSendable = 1;
  13958. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13959. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13960. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13961. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13962. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13963. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13964. }
  13965. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13966. {
  13967. mtrace();
  13968. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13969. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13970. }
  13971. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13972. {
  13973. mtrace();
  13974. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13975. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13976. }
  13977. void handleSignCertificateResponse(char *payload, int gun_index)
  13978. {
  13979. mtrace();
  13980. DEBUG_INFO("handleSignCertificateResponse...\n");
  13981. json_object *SignCertificate;
  13982. SignCertificate = json_tokener_parse(payload);
  13983. if(!is_error(SignCertificate))
  13984. {
  13985. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13986. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13987. }
  13988. json_object_put(SignCertificate);
  13989. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13990. }
  13991. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13992. {
  13993. mtrace();
  13994. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13995. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13996. }
  13997. //==========================================
  13998. // Handle Error routine
  13999. //==========================================
  14000. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14001. {
  14002. mtrace();
  14003. #ifdef SystemLogMessage
  14004. DEBUG_INFO("errorCode: %s\n", errorCode);
  14005. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14006. DEBUG_INFO("errorDetails: %s\n", payload);
  14007. #endif
  14008. }
  14009. //===============================================
  14010. // Common routine
  14011. //===============================================
  14012. int initialConfigurationTable(void)
  14013. {
  14014. //clock_t start_t, end_t, total_t;
  14015. FILE *fp;
  14016. FILE *outfile;
  14017. char str[512]={0};
  14018. char sstr[256]={0};
  14019. int c = 0;
  14020. char *loc;
  14021. int confVersion = 16;
  14022. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14023. //start_t = clock();
  14024. //printf("Starting of the program, start_t = %ld\n", start_t);
  14025. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14026. // Check configuration file size is correct
  14027. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  14028. {
  14029. struct stat st;
  14030. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  14031. if(st.st_size < 3100)
  14032. {
  14033. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  14034. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14035. }
  14036. }
  14037. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  14038. {
  14039. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14040. if(outfile == NULL)
  14041. {
  14042. DEBUG_INFO("Error opening file\n");
  14043. return FALSE;
  14044. }
  14045. /*Core Profile*/
  14046. //AllowOfflineTxForUnknownId
  14047. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14051. //AuthorizationCacheEnabled
  14052. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14053. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14054. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14056. //AuthorizeRemoteTxRequests
  14057. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14059. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14061. //BlinkRepeat
  14062. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14063. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14064. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14066. //ClockAlignedDataInterval
  14067. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14068. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14069. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14071. //ConnectionTimeOut
  14072. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14073. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14074. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14076. //GetConfigurationMaxKeys
  14077. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14079. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14081. // HeartbeatInterval
  14082. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14084. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14086. // LightIntensity
  14087. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14088. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14089. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14091. // LocalAuthorizeOffline
  14092. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14096. // LocalPreAuthorize
  14097. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14098. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14099. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14101. // MaxEnergyOnInvalidId
  14102. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14103. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14104. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14106. // MeterValuesAlignedData
  14107. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14109. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14110. 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" );
  14111. else
  14112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14114. // MeterValuesAlignedDataMaxLength
  14115. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14116. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14117. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14119. else
  14120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14122. // MeterValuesSampledData
  14123. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14125. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14126. 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" );
  14127. else
  14128. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14130. // MeterValuesSampledDataMaxLength
  14131. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14132. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14133. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14135. else
  14136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14138. // MeterValueSampleInterval
  14139. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14143. // MinimumStatusDuration
  14144. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14147. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14149. // NumberOfConnectors
  14150. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14151. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14152. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14153. {
  14154. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14155. }
  14156. else
  14157. {
  14158. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14159. }
  14160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14161. // ResetRetries
  14162. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14163. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14166. // ConnectorPhaseRotation
  14167. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14171. // ConnectorPhaseRotationMaxLength
  14172. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14173. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14174. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14176. // StopTransactionOnEVSideDisconnect
  14177. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14179. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14181. // StopTransactionOnInvalidId
  14182. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14183. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14186. // StopTxnAlignedData
  14187. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14188. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14191. // StopTxnAlignedDataMaxLength
  14192. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14193. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14194. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14196. // StopTxnSampledData
  14197. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14199. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14201. else
  14202. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14204. // StopTxnSampledDataMaxLength
  14205. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14207. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14208. {
  14209. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14210. }
  14211. else
  14212. {
  14213. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14214. }
  14215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14216. // SupportedFeatureProfiles
  14217. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14221. // SupportedFeatureProfilesMaxLength
  14222. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14223. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14224. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14226. // TransactionMessageAttempts
  14227. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14228. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14229. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14230. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14232. // TransactionMessageRetryInterval
  14233. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14236. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14238. // UnlockConnectorOnEVSideDisconnect
  14239. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14243. // WebSocketPingInterval
  14244. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14245. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14246. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14248. // QueueOffLineMeterValues
  14249. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14250. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14251. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14253. // AuthorizationKey
  14254. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14256. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  14257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14258. // SecurityProfile
  14259. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14261. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14263. // DefaultPrice
  14264. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14265. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14266. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14268. // CustomDisplayCostAndPrice
  14269. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14271. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14273. // CustomIdleFeeAfterStop
  14274. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14275. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14276. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14278. // SystemUptimeSec
  14279. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14280. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14281. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14283. // FreeVend
  14284. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14285. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14286. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14288. // FreeVendIdtag
  14289. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14293. // OcppServer
  14294. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14295. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14296. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14298. // MaintainServer
  14299. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14300. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14301. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14303. // StatusNotificationPeriodically
  14304. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14305. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14306. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14308. // StatusNotificationInterval
  14309. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14310. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14313. // isEnableLocalPowerSharing
  14314. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14315. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14316. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14318. // PowerSharingServerIP
  14319. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14320. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14321. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14323. // EVCCID_PREFIX
  14324. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14328. // OffLineMaxChargingPower
  14329. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  14330. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  14331. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  14332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  14333. // Configuration Version
  14334. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14335. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14336. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14338. //* Local Auth List Management Profile*/
  14339. #if 0
  14340. //For OCTT Test Case
  14341. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14344. #endif
  14345. #if 1
  14346. //LocalAuthListEnabled
  14347. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14349. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14351. #endif
  14352. //LocalAuthListMaxLength
  14353. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14354. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14355. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14357. //SendLocalListMaxLength
  14358. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14359. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  14361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14362. //ReserveConnectorZeroSupported
  14363. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14364. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14365. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14367. //* Smart Charging Profile */
  14368. //ChargeProfileMaxStackLevel
  14369. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14370. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14371. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14373. // ChargingScheduleAllowedChargingRateUnit
  14374. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14375. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14378. // ChargingScheduleMaxPeriods
  14379. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14380. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14381. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14383. // ConnectorSwitch3to1PhaseSupported
  14384. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14385. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14386. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14388. // MaxChargingProfilesInstalled
  14389. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14390. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14391. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14393. fclose(outfile);
  14394. }
  14395. else
  14396. {
  14397. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  14398. char keystr[60]={0};
  14399. char readonlystr[10]={0};
  14400. char valuestr[256]={0};
  14401. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  14402. if(fp == NULL) {
  14403. DEBUG_INFO("Error opening file");
  14404. return FALSE;
  14405. }
  14406. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14407. {
  14408. //DEBUG_INFO("Get Configuration \n");
  14409. if(strlen(str) > 0)
  14410. {
  14411. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14412. //*************************key*********************************/
  14413. if(strstr(str, "key") != NULL)
  14414. {
  14415. loc = strstr(str, "key");
  14416. c = 0;
  14417. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14418. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14419. {
  14420. sstr[c] = loc[strlen("key")+3+c];
  14421. c++;
  14422. }
  14423. sstr[c] = '\0';
  14424. strcpy(keystr,sstr);
  14425. }
  14426. //*************************readonly*********************************/
  14427. if(strstr(str, "readonly") != NULL)
  14428. {
  14429. loc = strstr(str, "readonly");
  14430. c = 0;
  14431. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14432. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14433. {
  14434. sstr[c] = loc[strlen("readonly")+2+c];
  14435. c++;
  14436. }
  14437. sstr[c] = '\0';
  14438. strcpy(readonlystr,sstr);
  14439. }
  14440. //*************************value*********************************/
  14441. if(strstr(str, "value") != NULL)
  14442. {
  14443. loc = strstr(str, "value");
  14444. c = 0;
  14445. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14446. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14447. {
  14448. sstr[c] = loc[strlen("value")+3+c];
  14449. c++;
  14450. }
  14451. sstr[c] = '\0';
  14452. strcpy(valuestr,sstr);
  14453. }
  14454. // DEBUG_INFO("keystr=%s\n",keystr);
  14455. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14456. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14457. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14458. {
  14459. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14460. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14461. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14462. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14463. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14464. }
  14465. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14466. {
  14467. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14468. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14469. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14470. }
  14471. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14472. {
  14473. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14474. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14475. }
  14476. if(strcmp(keystr, "BlinkRepeat") == 0)
  14477. {
  14478. //Charger.BlinkRepeat = Integer.parseInt(value);
  14479. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14480. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14481. }
  14482. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14483. {
  14484. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14485. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14486. }
  14487. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14488. {
  14489. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14490. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14491. }
  14492. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14493. {
  14494. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14495. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14496. }
  14497. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14498. {
  14499. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14500. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14501. HeartBeatWaitTime = atoi(valuestr);
  14502. }
  14503. if(strcmp(keystr, "LightIntensity") == 0)
  14504. {
  14505. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14506. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14507. }
  14508. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14509. {
  14510. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14511. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14512. }
  14513. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14514. {
  14515. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14516. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14517. }
  14518. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14519. {
  14520. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14521. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14522. }
  14523. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14524. {
  14525. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14526. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14527. }
  14528. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14529. {
  14530. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14531. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14532. }
  14533. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14534. {
  14535. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14536. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14537. }
  14538. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14539. {
  14540. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14541. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14542. }
  14543. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14544. {
  14545. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14546. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14547. }
  14548. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14549. {
  14550. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14551. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14552. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14553. }
  14554. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14555. {
  14556. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14557. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14558. }
  14559. if(strcmp(keystr, "ResetRetries") == 0)
  14560. {
  14561. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14562. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14563. }
  14564. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14565. {
  14566. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14567. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14568. }
  14569. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14570. {
  14571. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14572. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14573. }
  14574. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14575. {
  14576. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14577. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14578. }
  14579. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14580. {
  14581. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14582. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14583. }
  14584. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14585. {
  14586. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14587. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14588. }
  14589. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14590. {
  14591. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14592. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14593. }
  14594. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14595. {
  14596. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14597. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14598. }
  14599. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14600. {
  14601. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14602. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14603. }
  14604. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14605. {
  14606. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14607. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14608. }
  14609. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14610. {
  14611. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14612. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14613. }
  14614. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14615. {
  14616. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14617. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14618. TransactionMessageAttemptsValue = atoi(valuestr);
  14619. }
  14620. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14621. {
  14622. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14623. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14624. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14625. }
  14626. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14627. {
  14628. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14629. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14630. }
  14631. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14632. {
  14633. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14634. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14635. }
  14636. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14637. {
  14638. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14639. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14640. }
  14641. if(strcmp(keystr, "AuthorizationKey") == 0)
  14642. {
  14643. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14644. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14645. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14646. }
  14647. if(strcmp(keystr, "SecurityProfile") == 0)
  14648. {
  14649. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14650. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14651. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14652. }
  14653. if(strcmp(keystr, "DefaultPrice") == 0)
  14654. {
  14655. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14656. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14657. }
  14658. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14659. {
  14660. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14661. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14662. }
  14663. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14664. {
  14665. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14666. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14667. }
  14668. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14669. {
  14670. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14671. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14672. }
  14673. if(strcmp(keystr, "FreeVend") == 0)
  14674. {
  14675. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14676. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14677. }
  14678. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14679. {
  14680. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14681. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14682. }
  14683. if(strcmp(keystr, "OcppServer") == 0)
  14684. {
  14685. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14686. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14687. }
  14688. if(strcmp(keystr, "MaintainServer") == 0)
  14689. {
  14690. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14691. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14692. }
  14693. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14694. {
  14695. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14696. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14697. }
  14698. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14699. {
  14700. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14701. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14702. }
  14703. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14704. {
  14705. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14706. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14707. }
  14708. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14709. {
  14710. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14711. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14712. }
  14713. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14714. {
  14715. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14716. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14717. }
  14718. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  14719. {
  14720. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14721. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  14722. }
  14723. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14724. {
  14725. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14726. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14727. }
  14728. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14729. {
  14730. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14731. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14732. }
  14733. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14734. {
  14735. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14736. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14737. }
  14738. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14739. {
  14740. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14741. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14742. }
  14743. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14744. {
  14745. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14746. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14747. }
  14748. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14749. {
  14750. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14751. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14752. }
  14753. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14754. {
  14755. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14756. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14757. }
  14758. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14759. {
  14760. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14761. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14762. }
  14763. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14764. {
  14765. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14766. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14767. }
  14768. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14769. {
  14770. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14771. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14772. }
  14773. }
  14774. }
  14775. fclose(fp);
  14776. }
  14777. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14778. {
  14779. return PASS;
  14780. }
  14781. else
  14782. {
  14783. return FAIL;
  14784. }
  14785. }
  14786. void StoreConfigurationTable(void)
  14787. {
  14788. FILE *outfile;
  14789. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14790. if(outfile == NULL)
  14791. {
  14792. DEBUG_INFO("Error opening file");
  14793. return ;
  14794. }
  14795. /*Core Profile*/
  14796. //AllowOfflineTxForUnknownId
  14797. /*
  14798. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14799. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14800. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14801. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14802. */
  14803. //DEBUG_INFO("data=%s\n",data);
  14804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14805. //AuthorizationCacheEnabled
  14806. /*
  14807. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14808. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14809. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14810. */
  14811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14812. //AuthorizeRemoteTxRequests
  14813. /*
  14814. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14815. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14816. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14817. */
  14818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14819. //BlinkRepeat
  14820. /*
  14821. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14822. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14823. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14824. */
  14825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14826. //ClockAlignedDataInterval
  14827. /*
  14828. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14831. */
  14832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14833. //ConnectionTimeOut
  14834. /*
  14835. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14836. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14837. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14838. */
  14839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14840. //GetConfigurationMaxKeys
  14841. /*
  14842. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14843. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14845. */
  14846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14847. // HeartbeatInterval
  14848. /*
  14849. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14852. */
  14853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14854. // LightIntensity
  14855. /*
  14856. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14857. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14858. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14859. */
  14860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14861. // LocalAuthorizeOffline
  14862. /*
  14863. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14864. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14866. */
  14867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14868. // LocalPreAuthorize
  14869. /*
  14870. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14871. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14873. */
  14874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14875. // MaxEnergyOnInvalidId
  14876. /*
  14877. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14878. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14879. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14880. */
  14881. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14883. // MeterValuesAlignedData
  14884. /*
  14885. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14886. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14888. */
  14889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14890. // MeterValuesAlignedDataMaxLength
  14891. /*
  14892. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14893. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14894. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14895. */
  14896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14897. // MeterValuesSampledData
  14898. /*
  14899. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14900. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14901. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14902. */
  14903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14904. // MeterValuesSampledDataMaxLength
  14905. /*
  14906. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14907. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14908. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14909. */
  14910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14911. // MeterValueSampleInterval
  14912. /*
  14913. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14914. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14916. */
  14917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14918. // MinimumStatusDuration
  14919. /*
  14920. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14921. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14922. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14923. */
  14924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14925. // NumberOfConnectors
  14926. /*
  14927. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14929. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14930. {
  14931. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14932. }
  14933. else
  14934. {
  14935. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14936. }
  14937. */
  14938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14939. // ResetRetries
  14940. /*
  14941. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14944. */
  14945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14946. // ConnectorPhaseRotation
  14947. /*
  14948. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14949. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14950. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14951. */
  14952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14953. // ConnectorPhaseRotationMaxLength
  14954. /*
  14955. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14956. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14958. */
  14959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14960. // StopTransactionOnEVSideDisconnect
  14961. /*
  14962. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14963. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14965. */
  14966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14967. // StopTransactionOnInvalidId
  14968. /*
  14969. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14972. */
  14973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14974. // StopTxnAlignedData
  14975. /*
  14976. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14977. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14979. */
  14980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14981. // StopTxnAlignedDataMaxLength
  14982. /*
  14983. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14984. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14985. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14986. */
  14987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14988. // StopTxnSampledData
  14989. /*
  14990. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14991. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14993. */
  14994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14995. // StopTxnSampledDataMaxLength
  14996. /*
  14997. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14998. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14999. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  15000. */
  15001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15002. // SupportedFeatureProfiles
  15003. /*
  15004. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15005. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15007. */
  15008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15009. // SupportedFeatureProfilesMaxLength
  15010. /*
  15011. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15012. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15013. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15014. */
  15015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15016. // TransactionMessageAttempts
  15017. /*
  15018. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15019. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15020. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15021. */
  15022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15023. // TransactionMessageRetryInterval
  15024. /*
  15025. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15026. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15027. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15028. */
  15029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15030. // UnlockConnectorOnEVSideDisconnect
  15031. /*
  15032. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15033. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15034. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15035. */
  15036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15037. // WebSocketPingInterval
  15038. /*
  15039. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15040. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15041. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15042. */
  15043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15044. // QueueOffLineMeterValues
  15045. /*
  15046. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15047. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15049. */
  15050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15051. // AuthorizationKey
  15052. /*
  15053. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15054. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15055. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15056. */
  15057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15058. // SecurityProfile
  15059. /*
  15060. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15061. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15063. */
  15064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15065. // DefaultPrice
  15066. /*
  15067. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15068. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15069. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15070. */
  15071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15072. // CustomDisplayCostAndPrice
  15073. /*
  15074. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15075. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15076. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15077. */
  15078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15079. // CustomIdleFeeAfterStop
  15080. /*
  15081. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15082. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15084. */
  15085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15086. // SystemUptimeSec
  15087. /*
  15088. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15089. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15090. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15091. */
  15092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15093. // FreeVend
  15094. /*
  15095. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15096. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15098. */
  15099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15100. // FreeVendIdtag
  15101. /*
  15102. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15103. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15104. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15105. */
  15106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15107. // OcppServer
  15108. /*
  15109. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15110. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15111. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15112. */
  15113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15114. // MaintainServer
  15115. /*
  15116. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15117. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15119. */
  15120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15121. // StatusNotificationPeriodically
  15122. /*
  15123. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15126. */
  15127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15128. // StatusNotificationInterval
  15129. /*
  15130. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15132. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15133. */
  15134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15135. // isEnableLocalPowerSharing
  15136. /*
  15137. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15140. */
  15141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15142. // PowerSharingServerIP
  15143. /*
  15144. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15147. */
  15148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15149. // EVCCID_PREFIX
  15150. /*
  15151. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15154. */
  15155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15156. // OffLineMaxChargingPower
  15157. /*
  15158. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  15161. */
  15162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15163. // ConfigurationVersion
  15164. /*
  15165. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15166. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15168. */
  15169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15170. //* Local Auth List Management Profile*/
  15171. //LocalAuthListEnabled
  15172. /*
  15173. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15174. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15176. */
  15177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15178. //LocalAuthListMaxLength
  15179. /*
  15180. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15183. */
  15184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15185. //SendLocalListMaxLength
  15186. /*
  15187. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15188. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15190. */
  15191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15192. //ReserveConnectorZeroSupported
  15193. /*
  15194. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15197. */
  15198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15199. //* Smart Charging Profile */
  15200. //ChargeProfileMaxStackLevel
  15201. /*
  15202. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15205. */
  15206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15207. // ChargingScheduleAllowedChargingRateUnit
  15208. /*
  15209. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15210. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15212. */
  15213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15214. // ChargingScheduleMaxPeriods
  15215. /*
  15216. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15219. */
  15220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15221. // ConnectorSwitch3to1PhaseSupported
  15222. /*
  15223. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15224. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15225. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15226. */
  15227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15228. // MaxChargingProfilesInstalled
  15229. /*
  15230. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15231. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15232. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15233. */
  15234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15235. fclose(outfile);
  15236. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15237. }
  15238. void getKeyValue(char *keyReq)
  15239. {
  15240. int isEmpty = FALSE;
  15241. int isKnowKey = FALSE;
  15242. DEBUG_INFO("keyReq = %s\n", keyReq);
  15243. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15244. isEmpty = TRUE;
  15245. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15246. {
  15247. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15248. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15249. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15250. {
  15251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15252. }
  15253. else
  15254. {
  15255. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15256. }
  15257. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15258. isKnowKey = TRUE;
  15259. }
  15260. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15261. {
  15262. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15263. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15264. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15265. {
  15266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15267. }
  15268. else
  15269. {
  15270. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15271. }
  15272. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15273. isKnowKey = TRUE;
  15274. }
  15275. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15276. {
  15277. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15278. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15279. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15280. {
  15281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15282. }
  15283. else
  15284. {
  15285. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15286. }
  15287. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15288. isKnowKey = TRUE;
  15289. }
  15290. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15291. {
  15292. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15293. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15294. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15295. {
  15296. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15297. }
  15298. else
  15299. {
  15300. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15301. }
  15302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15303. isKnowKey = TRUE;
  15304. }
  15305. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15306. {
  15307. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15309. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15310. {
  15311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15312. }
  15313. else
  15314. {
  15315. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15316. }
  15317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15318. isKnowKey = TRUE;
  15319. }
  15320. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15321. {
  15322. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15324. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15325. {
  15326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15327. }
  15328. else
  15329. {
  15330. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15331. }
  15332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15333. isKnowKey = TRUE;
  15334. }
  15335. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15336. {
  15337. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15339. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15340. {
  15341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15342. }
  15343. else
  15344. {
  15345. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15346. }
  15347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15348. isKnowKey = TRUE;
  15349. }
  15350. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15351. {
  15352. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15354. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15355. {
  15356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15357. }
  15358. else
  15359. {
  15360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15361. }
  15362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15363. isKnowKey = TRUE;
  15364. }
  15365. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15366. {
  15367. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15369. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15370. {
  15371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15372. }
  15373. else
  15374. {
  15375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15376. }
  15377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15378. isKnowKey = TRUE;
  15379. }
  15380. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15381. {
  15382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15384. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15385. {
  15386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15387. }
  15388. else
  15389. {
  15390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15391. }
  15392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15393. isKnowKey = TRUE;
  15394. }
  15395. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15396. {
  15397. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15399. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15400. {
  15401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15402. }
  15403. else
  15404. {
  15405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15406. }
  15407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15408. isKnowKey = TRUE;
  15409. }
  15410. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15411. {
  15412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15414. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15415. {
  15416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15417. }
  15418. else
  15419. {
  15420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15421. }
  15422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15423. isKnowKey = TRUE;
  15424. }
  15425. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15426. {
  15427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15429. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15430. {
  15431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15432. }
  15433. else
  15434. {
  15435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15436. }
  15437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15438. isKnowKey = TRUE;
  15439. }
  15440. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15441. {
  15442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15444. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15445. {
  15446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15447. }
  15448. else
  15449. {
  15450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15451. }
  15452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15453. isKnowKey = TRUE;
  15454. }
  15455. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15456. {
  15457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15459. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15460. {
  15461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15462. }
  15463. else
  15464. {
  15465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15466. }
  15467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15468. isKnowKey = TRUE;
  15469. }
  15470. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15471. {
  15472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15474. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15475. {
  15476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15477. }
  15478. else
  15479. {
  15480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15481. }
  15482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15483. isKnowKey = TRUE;
  15484. }
  15485. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15486. {
  15487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15489. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15490. {
  15491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15492. }
  15493. else
  15494. {
  15495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15496. }
  15497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15498. isKnowKey = TRUE;
  15499. }
  15500. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15501. {
  15502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15504. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15505. {
  15506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15507. }
  15508. else
  15509. {
  15510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15511. }
  15512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  15513. isKnowKey = TRUE;
  15514. }
  15515. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15516. {
  15517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15519. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15520. {
  15521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15522. }
  15523. else
  15524. {
  15525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15526. }
  15527. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15528. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15529. isKnowKey = TRUE;
  15530. }
  15531. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15532. {
  15533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15535. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15536. {
  15537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15538. }
  15539. else
  15540. {
  15541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15542. }
  15543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15544. isKnowKey = TRUE;
  15545. }
  15546. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15547. {
  15548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15550. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15551. {
  15552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15553. }
  15554. else
  15555. {
  15556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15557. }
  15558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15559. isKnowKey = TRUE;
  15560. }
  15561. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15562. {
  15563. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15565. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15566. {
  15567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15568. }
  15569. else
  15570. {
  15571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15572. }
  15573. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15574. isKnowKey = TRUE;
  15575. }
  15576. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15577. {
  15578. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15580. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15581. {
  15582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15583. }
  15584. else
  15585. {
  15586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15587. }
  15588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15589. isKnowKey = TRUE;
  15590. }
  15591. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15592. {
  15593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15595. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15596. {
  15597. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15598. }
  15599. else
  15600. {
  15601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15602. }
  15603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15604. isKnowKey = TRUE;
  15605. }
  15606. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15607. {
  15608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15610. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15611. {
  15612. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15613. }
  15614. else
  15615. {
  15616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15617. }
  15618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15619. isKnowKey = TRUE;
  15620. }
  15621. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15622. {
  15623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15625. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15626. {
  15627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15628. }
  15629. else
  15630. {
  15631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15632. }
  15633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15634. isKnowKey = TRUE;
  15635. }
  15636. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15637. {
  15638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15639. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15640. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15641. {
  15642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15643. }
  15644. else
  15645. {
  15646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15647. }
  15648. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15649. isKnowKey = TRUE;
  15650. }
  15651. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15652. {
  15653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15654. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15655. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15656. {
  15657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15658. }
  15659. else
  15660. {
  15661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15662. }
  15663. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15664. isKnowKey = TRUE;
  15665. }
  15666. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15667. {
  15668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15669. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15670. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15671. {
  15672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15673. }
  15674. else
  15675. {
  15676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15677. }
  15678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15679. isKnowKey = TRUE;
  15680. }
  15681. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15682. {
  15683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15685. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15686. {
  15687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15688. }
  15689. else
  15690. {
  15691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15692. }
  15693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15694. isKnowKey = TRUE;
  15695. }
  15696. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15697. {
  15698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15699. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15700. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15701. {
  15702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15703. }
  15704. else
  15705. {
  15706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15707. }
  15708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15709. isKnowKey = TRUE;
  15710. }
  15711. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15712. {
  15713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15715. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15716. {
  15717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15718. }
  15719. else
  15720. {
  15721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15722. }
  15723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15724. isKnowKey = TRUE;
  15725. }
  15726. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15727. {
  15728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15730. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15731. {
  15732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15733. }
  15734. else
  15735. {
  15736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15737. }
  15738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15739. isKnowKey = TRUE;
  15740. }
  15741. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15742. {
  15743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15744. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15745. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15746. {
  15747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15748. }
  15749. else
  15750. {
  15751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15752. }
  15753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15754. isKnowKey = TRUE;
  15755. }
  15756. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15757. {
  15758. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15759. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15760. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15761. {
  15762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15763. }
  15764. else
  15765. {
  15766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15767. }
  15768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15769. isKnowKey = TRUE;
  15770. }
  15771. /*
  15772. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15773. {
  15774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15776. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15777. {
  15778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15779. }
  15780. else
  15781. {
  15782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15783. }
  15784. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15785. isKnowKey = TRUE;
  15786. }*/
  15787. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15788. {
  15789. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15791. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15792. {
  15793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15794. }
  15795. else
  15796. {
  15797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15798. }
  15799. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15800. isKnowKey = TRUE;
  15801. }
  15802. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15803. {
  15804. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15806. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15807. {
  15808. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15809. }
  15810. else
  15811. {
  15812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15813. }
  15814. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15815. isKnowKey = TRUE;
  15816. }
  15817. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15818. {
  15819. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15820. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15821. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15822. {
  15823. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15824. }
  15825. else
  15826. {
  15827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15828. }
  15829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15830. isKnowKey = TRUE;
  15831. }
  15832. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15833. {
  15834. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15836. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15837. {
  15838. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15839. }
  15840. else
  15841. {
  15842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15843. }
  15844. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15845. isKnowKey = TRUE;
  15846. }
  15847. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15848. {
  15849. struct sysinfo s_info;
  15850. int error = sysinfo(&s_info);
  15851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15852. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15853. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15854. {
  15855. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15856. }
  15857. else
  15858. {
  15859. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15860. }
  15861. if(error != 0)
  15862. {
  15863. DEBUG_WARN("System uptime get error: %d\n", error);
  15864. }
  15865. else
  15866. {
  15867. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15868. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15869. }
  15870. isKnowKey = TRUE;
  15871. }
  15872. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15873. {
  15874. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15875. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15876. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15877. {
  15878. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15879. }
  15880. else
  15881. {
  15882. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15883. }
  15884. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15885. isKnowKey = TRUE;
  15886. }
  15887. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15888. {
  15889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15890. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15891. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15892. {
  15893. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15894. }
  15895. else
  15896. {
  15897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15898. }
  15899. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15900. isKnowKey = TRUE;
  15901. }
  15902. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15903. {
  15904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15905. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15906. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15907. {
  15908. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15909. }
  15910. else
  15911. {
  15912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15913. }
  15914. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15915. isKnowKey = TRUE;
  15916. }
  15917. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15918. {
  15919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15920. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15921. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15922. {
  15923. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15924. }
  15925. else
  15926. {
  15927. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15928. }
  15929. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15930. isKnowKey = TRUE;
  15931. }
  15932. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15933. {
  15934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15935. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15936. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15937. {
  15938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15939. }
  15940. else
  15941. {
  15942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15943. }
  15944. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15945. isKnowKey = TRUE;
  15946. }
  15947. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15948. {
  15949. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15950. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15951. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15952. {
  15953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15954. }
  15955. else
  15956. {
  15957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15958. }
  15959. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15960. isKnowKey = TRUE;
  15961. }
  15962. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  15963. {
  15964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  15965. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  15966. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  15967. {
  15968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  15969. }
  15970. else
  15971. {
  15972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  15973. }
  15974. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  15975. isKnowKey = TRUE;
  15976. }
  15977. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  15978. {
  15979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  15980. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  15981. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  15982. {
  15983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  15984. }
  15985. else
  15986. {
  15987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  15988. }
  15989. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  15990. isKnowKey = TRUE;
  15991. }
  15992. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  15993. {
  15994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  15995. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  15996. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  15997. {
  15998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  15999. }
  16000. else
  16001. {
  16002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  16003. }
  16004. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  16005. isKnowKey = TRUE;
  16006. }
  16007. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  16008. {
  16009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  16010. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  16011. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  16012. {
  16013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  16014. }
  16015. else
  16016. {
  16017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  16018. }
  16019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  16020. isKnowKey = TRUE;
  16021. }
  16022. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16023. {
  16024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16025. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16026. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16027. {
  16028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16029. }
  16030. else
  16031. {
  16032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16033. }
  16034. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16035. isKnowKey = TRUE;
  16036. }
  16037. #if 1
  16038. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16039. {
  16040. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16042. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16043. {
  16044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16045. }
  16046. else
  16047. {
  16048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16049. }
  16050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16051. isKnowKey = TRUE;
  16052. }
  16053. #endif
  16054. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16055. {
  16056. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16058. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16059. {
  16060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16061. }
  16062. else
  16063. {
  16064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16065. }
  16066. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16067. isKnowKey = TRUE;
  16068. }
  16069. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16070. {
  16071. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16073. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16074. {
  16075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16076. }
  16077. else
  16078. {
  16079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16080. }
  16081. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16082. isKnowKey = TRUE;
  16083. }
  16084. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16085. {
  16086. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16088. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16089. {
  16090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16091. }
  16092. else
  16093. {
  16094. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16095. }
  16096. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16097. isKnowKey = TRUE;
  16098. }
  16099. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16100. {
  16101. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16102. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16103. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16104. {
  16105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16106. }
  16107. else
  16108. {
  16109. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16110. }
  16111. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16112. isKnowKey = TRUE;
  16113. }
  16114. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16115. {
  16116. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16118. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16119. {
  16120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16121. }
  16122. else
  16123. {
  16124. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16125. }
  16126. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16127. isKnowKey = TRUE;
  16128. }
  16129. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16130. {
  16131. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16133. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16134. {
  16135. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16136. }
  16137. else
  16138. {
  16139. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16140. }
  16141. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16142. isKnowKey = TRUE;
  16143. }
  16144. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16145. {
  16146. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16147. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16148. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16149. {
  16150. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16151. }
  16152. else
  16153. {
  16154. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16155. }
  16156. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16157. isKnowKey = TRUE;
  16158. }
  16159. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16160. {
  16161. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16162. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16163. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16164. {
  16165. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16166. }
  16167. else
  16168. {
  16169. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16170. }
  16171. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16172. isKnowKey = TRUE;
  16173. }
  16174. //=========================================================
  16175. if(!isEmpty && !isKnowKey)
  16176. {
  16177. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16178. strcpy(unknownkey[UnknownKeynum], keyReq);
  16179. UnknownKeynum = UnknownKeynum + 1;
  16180. }
  16181. }
  16182. void processUnkownKey(void)
  16183. {
  16184. DEBUG_INFO("processUnkownKey...\n");
  16185. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16186. for(int index=0; index < UnknownKeynum; index++)
  16187. {
  16188. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16189. {
  16190. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16191. }
  16192. }
  16193. }
  16194. int setKeyValue(char *key, char *value)
  16195. {
  16196. int isSuccess = NotSupported;
  16197. int check_ascii=0;
  16198. char str[501]={0};
  16199. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16200. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16201. {
  16202. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16203. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16204. {
  16205. strcpy(str, (const char*)value);
  16206. for(int i = 0; str[i]; i++){
  16207. str[i] = tolower(str[i]);
  16208. }
  16209. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16210. isSuccess = ConfigurationStatus_Accepted;
  16211. }
  16212. else
  16213. {
  16214. isSuccess = ConfigurationStatus_Rejected;
  16215. }
  16216. }
  16217. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16218. {
  16219. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16220. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16221. {
  16222. strcpy(str, (const char*)value);
  16223. for(int i = 0; str[i]; i++){
  16224. str[i] = tolower(str[i]);
  16225. }
  16226. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16227. isSuccess = ConfigurationStatus_Accepted;
  16228. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  16229. }
  16230. else
  16231. {
  16232. isSuccess = ConfigurationStatus_Rejected;
  16233. }
  16234. }
  16235. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16236. {
  16237. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16238. {
  16239. strcpy(str, (const char*)value);
  16240. for(int i = 0; str[i]; i++)
  16241. {
  16242. str[i] = tolower(str[i]);
  16243. }
  16244. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16245. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16246. isSuccess = ConfigurationStatus_Accepted;
  16247. }
  16248. else
  16249. {
  16250. isSuccess = ConfigurationStatus_Rejected;
  16251. }
  16252. }
  16253. if(strcmp(key, "BlinkRepeat") == 0)
  16254. {
  16255. //Charger.BlinkRepeat = Integer.parseInt(value);
  16256. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16257. {
  16258. check_ascii = value[0];
  16259. if( (check_ascii < 48) || (check_ascii > 57) )
  16260. {
  16261. isSuccess = ConfigurationStatus_Rejected;
  16262. }
  16263. else
  16264. {
  16265. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16266. isSuccess = ConfigurationStatus_Accepted;
  16267. }
  16268. }
  16269. else
  16270. {
  16271. isSuccess = ConfigurationStatus_Rejected;
  16272. }
  16273. }
  16274. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16275. {
  16276. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16277. {
  16278. check_ascii = value[0];
  16279. if( (check_ascii < 48) || (check_ascii > 57) )
  16280. {
  16281. isSuccess = ConfigurationStatus_Rejected;
  16282. }
  16283. else
  16284. {
  16285. if((atoi(value) == 0) || (atoi(value) >= 5))
  16286. {
  16287. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16288. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16289. isSuccess = ConfigurationStatus_Accepted;
  16290. }
  16291. else
  16292. isSuccess = ConfigurationStatus_Rejected;
  16293. }
  16294. }
  16295. else
  16296. {
  16297. isSuccess = ConfigurationStatus_Rejected;
  16298. }
  16299. }
  16300. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16301. {
  16302. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16303. {
  16304. check_ascii = value[0];
  16305. if( (check_ascii < 48) || (check_ascii > 57) )
  16306. {
  16307. isSuccess = ConfigurationStatus_Rejected;
  16308. }
  16309. else
  16310. {
  16311. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16312. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16313. isSuccess = ConfigurationStatus_Accepted;
  16314. }
  16315. }
  16316. else
  16317. {
  16318. isSuccess = ConfigurationStatus_Rejected;
  16319. }
  16320. }
  16321. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16322. {
  16323. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].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. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16333. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16334. isSuccess = ConfigurationStatus_Accepted;
  16335. }
  16336. }
  16337. else
  16338. {
  16339. isSuccess = ConfigurationStatus_Rejected;
  16340. }
  16341. }
  16342. if(strcmp(key, "HeartbeatInterval") == 0)
  16343. {
  16344. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16345. {
  16346. check_ascii = value[0];
  16347. if( (check_ascii < 48) || (check_ascii > 57) )
  16348. {
  16349. isSuccess = ConfigurationStatus_Rejected;
  16350. }
  16351. else
  16352. {
  16353. if((atoi(value) == 0) || (atoi(value) >= 10))
  16354. {
  16355. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16356. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16357. HeartBeatWaitTime = atoi(value);
  16358. isSuccess = ConfigurationStatus_Accepted;
  16359. }
  16360. else
  16361. {
  16362. isSuccess = ConfigurationStatus_Rejected;
  16363. }
  16364. }
  16365. }
  16366. else
  16367. {
  16368. isSuccess = ConfigurationStatus_Rejected;
  16369. }
  16370. }
  16371. if(strcmp(key, "LightIntensity") == 0)
  16372. {
  16373. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16374. {
  16375. check_ascii = value[0];
  16376. if( (check_ascii < 48) || (check_ascii > 57) )
  16377. {
  16378. isSuccess = ConfigurationStatus_Rejected;
  16379. }
  16380. else
  16381. {
  16382. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16383. isSuccess = ConfigurationStatus_Accepted;
  16384. }
  16385. }
  16386. else
  16387. {
  16388. isSuccess = ConfigurationStatus_Rejected;
  16389. }
  16390. }
  16391. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16392. {
  16393. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16394. {
  16395. strcpy(str, (const char*)value);
  16396. for(int i = 0; str[i]; i++)
  16397. {
  16398. str[i] = tolower(str[i]);
  16399. }
  16400. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16401. isSuccess = ConfigurationStatus_Accepted;
  16402. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16403. }
  16404. else
  16405. {
  16406. isSuccess = ConfigurationStatus_Rejected;
  16407. }
  16408. }
  16409. if(strcmp(key, "LocalPreAuthorize") == 0)
  16410. {
  16411. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16412. {
  16413. strcpy(str, (const char*)value);
  16414. for(int i = 0; str[i]; i++)
  16415. {
  16416. str[i] = tolower(str[i]);
  16417. }
  16418. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16419. isSuccess = ConfigurationStatus_Accepted;
  16420. }
  16421. else
  16422. {
  16423. isSuccess = ConfigurationStatus_Rejected;
  16424. }
  16425. }
  16426. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16427. {
  16428. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16429. {
  16430. check_ascii = value[0];
  16431. if( (check_ascii < 48) || (check_ascii > 57) )
  16432. {
  16433. isSuccess = ConfigurationStatus_Rejected;
  16434. }
  16435. else
  16436. {
  16437. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16438. isSuccess = ConfigurationStatus_Accepted;
  16439. }
  16440. }
  16441. else
  16442. {
  16443. isSuccess = ConfigurationStatus_Rejected;
  16444. }
  16445. }
  16446. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16447. {
  16448. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16449. {
  16450. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16451. isSuccess = ConfigurationStatus_Accepted;
  16452. }
  16453. else
  16454. {
  16455. isSuccess = ConfigurationStatus_Rejected;
  16456. }
  16457. }
  16458. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16459. {
  16460. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16461. {
  16462. check_ascii = value[0];
  16463. if( (check_ascii < 48) || (check_ascii > 57) )
  16464. {
  16465. isSuccess = ConfigurationStatus_Rejected;
  16466. }
  16467. else
  16468. {
  16469. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16470. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16471. isSuccess = ConfigurationStatus_Accepted;
  16472. }
  16473. }
  16474. else
  16475. {
  16476. isSuccess = ConfigurationStatus_Rejected;
  16477. }
  16478. }
  16479. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16480. {
  16481. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16482. {
  16483. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16484. isSuccess = ConfigurationStatus_Accepted;
  16485. }
  16486. else
  16487. {
  16488. isSuccess = ConfigurationStatus_Rejected;
  16489. }
  16490. }
  16491. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16492. {
  16493. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16494. {
  16495. check_ascii = value[0];
  16496. if( (check_ascii < 48) || (check_ascii > 57) )
  16497. {
  16498. isSuccess = ConfigurationStatus_Rejected;
  16499. }
  16500. else
  16501. {
  16502. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16503. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16504. isSuccess = ConfigurationStatus_Accepted;
  16505. }
  16506. }
  16507. else
  16508. {
  16509. isSuccess = ConfigurationStatus_Rejected;
  16510. }
  16511. }
  16512. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16513. {
  16514. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16515. {
  16516. check_ascii = value[0];
  16517. if( (check_ascii < 48) || (check_ascii > 57) )
  16518. {
  16519. isSuccess = ConfigurationStatus_Rejected;
  16520. }
  16521. else
  16522. {
  16523. if((atoi(value) == 0) || (atoi(value) >= 3))
  16524. {
  16525. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16526. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16527. isSuccess = ConfigurationStatus_Accepted;
  16528. }
  16529. else
  16530. {
  16531. isSuccess = ConfigurationStatus_Rejected;
  16532. }
  16533. }
  16534. }
  16535. else
  16536. {
  16537. isSuccess = ConfigurationStatus_Rejected;
  16538. }
  16539. }
  16540. if(strcmp(key, "MinimumStatusDuration") == 0)
  16541. {
  16542. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16543. {
  16544. check_ascii = value[0];
  16545. if( (check_ascii < 48) || (check_ascii > 57) )
  16546. {
  16547. isSuccess = ConfigurationStatus_Rejected;
  16548. }
  16549. else
  16550. {
  16551. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16552. {
  16553. isSuccess = ConfigurationStatus_Rejected;
  16554. }
  16555. else
  16556. {
  16557. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16558. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16559. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16560. isSuccess = ConfigurationStatus_Accepted;
  16561. }
  16562. }
  16563. }
  16564. else
  16565. {
  16566. isSuccess = ConfigurationStatus_Rejected;
  16567. }
  16568. }
  16569. if(strcmp(key, "NumberOfConnectors") == 0)
  16570. {
  16571. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16572. {
  16573. check_ascii = value[0];
  16574. if( (check_ascii < 48) || (check_ascii > 57) )
  16575. {
  16576. isSuccess = ConfigurationStatus_Rejected;
  16577. }
  16578. else
  16579. {
  16580. //Charger.ResetRetries = Integer.parseInt(value);
  16581. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16582. isSuccess = ConfigurationStatus_Accepted;
  16583. }
  16584. }
  16585. else
  16586. {
  16587. isSuccess = ConfigurationStatus_Rejected;
  16588. }
  16589. }
  16590. if(strcmp(key, "ResetRetries") == 0)
  16591. {
  16592. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16593. {
  16594. check_ascii = value[0];
  16595. if( (check_ascii < 48) || (check_ascii > 57) )
  16596. {
  16597. isSuccess = ConfigurationStatus_Rejected;
  16598. }
  16599. else
  16600. {
  16601. //Charger.ResetRetries = Integer.parseInt(value);
  16602. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16603. isSuccess = ConfigurationStatus_Accepted;
  16604. }
  16605. }
  16606. else
  16607. {
  16608. isSuccess = ConfigurationStatus_Rejected;
  16609. }
  16610. }
  16611. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16612. {
  16613. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16614. {
  16615. strcpy(str, (const char*)value);
  16616. for(int i = 0; str[i]; i++)
  16617. {
  16618. str[i] = tolower(str[i]);
  16619. }
  16620. if(strcmp(str, "notapplicable")== 0)
  16621. {
  16622. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16623. isSuccess = ConfigurationStatus_Accepted;
  16624. }
  16625. else if(strcmp(str, "unknown")== 0)
  16626. {
  16627. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16628. isSuccess = ConfigurationStatus_Accepted;
  16629. }
  16630. else if(strcmp(str, "rst")== 0)
  16631. {
  16632. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16633. isSuccess = ConfigurationStatus_Accepted;
  16634. }
  16635. else if(strcmp(str, "rts")== 0)
  16636. {
  16637. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16638. isSuccess = ConfigurationStatus_Accepted;
  16639. }
  16640. else if(strcmp(str, "srt")== 0)
  16641. {
  16642. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16643. isSuccess = ConfigurationStatus_Accepted;
  16644. }
  16645. else if(strcmp(str, "str")== 0)
  16646. {
  16647. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16648. isSuccess = ConfigurationStatus_Accepted;
  16649. }
  16650. else if(strcmp(str, "trs")== 0)
  16651. {
  16652. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16653. isSuccess = ConfigurationStatus_Accepted;
  16654. }
  16655. else if(strcmp(str, "tsr")== 0)
  16656. {
  16657. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16658. isSuccess = ConfigurationStatus_Accepted;
  16659. }
  16660. else
  16661. {
  16662. isSuccess = ConfigurationStatus_Rejected;
  16663. }
  16664. }
  16665. else
  16666. {
  16667. isSuccess = ConfigurationStatus_Rejected;
  16668. }
  16669. }
  16670. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16671. {
  16672. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16673. {
  16674. check_ascii = value[0];
  16675. if( (check_ascii < 48) || (check_ascii > 57) )
  16676. {
  16677. isSuccess = ConfigurationStatus_Rejected;
  16678. }
  16679. else
  16680. {
  16681. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16682. isSuccess = ConfigurationStatus_Accepted;
  16683. }
  16684. }
  16685. else
  16686. {
  16687. isSuccess = ConfigurationStatus_Rejected;
  16688. }
  16689. }
  16690. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16691. {
  16692. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16693. {
  16694. strcpy(str, (const char*)value);
  16695. for(int i = 0; str[i]; i++)
  16696. {
  16697. str[i] = tolower(str[i]);
  16698. }
  16699. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16700. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16701. isSuccess = ConfigurationStatus_Accepted;
  16702. }
  16703. else
  16704. {
  16705. isSuccess = ConfigurationStatus_Rejected;
  16706. }
  16707. }
  16708. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16709. {
  16710. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16711. {
  16712. strcpy(str, (const char*)value);
  16713. for(int i = 0; str[i]; i++)
  16714. {
  16715. str[i] = tolower(str[i]);
  16716. }
  16717. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16718. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16719. isSuccess = ConfigurationStatus_Accepted;
  16720. }
  16721. else
  16722. {
  16723. isSuccess = ConfigurationStatus_Rejected;
  16724. }
  16725. }
  16726. if(strcmp(key, "StopTxnAlignedData") == 0)
  16727. {
  16728. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16729. {
  16730. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16731. isSuccess = ConfigurationStatus_Accepted;
  16732. }
  16733. else
  16734. {
  16735. isSuccess = ConfigurationStatus_Rejected;
  16736. }
  16737. }
  16738. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16739. {
  16740. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16741. {
  16742. check_ascii = value[0];
  16743. if( (check_ascii < 48) || (check_ascii > 57) )
  16744. {
  16745. isSuccess = ConfigurationStatus_Rejected;
  16746. }
  16747. else
  16748. {
  16749. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16750. isSuccess = ConfigurationStatus_Accepted;
  16751. }
  16752. }
  16753. else
  16754. {
  16755. isSuccess = ConfigurationStatus_Rejected;
  16756. }
  16757. }
  16758. if(strcmp(key, "StopTxnSampledData") == 0)
  16759. {
  16760. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16761. {
  16762. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16763. isSuccess = ConfigurationStatus_Accepted;
  16764. }
  16765. else
  16766. {
  16767. isSuccess = ConfigurationStatus_Rejected;
  16768. }
  16769. }
  16770. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16771. {
  16772. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16773. {
  16774. check_ascii = value[0];
  16775. if( (check_ascii < 48) || (check_ascii > 57) )
  16776. {
  16777. isSuccess = ConfigurationStatus_Rejected;
  16778. }
  16779. else
  16780. {
  16781. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16782. isSuccess = ConfigurationStatus_Accepted;
  16783. }
  16784. }
  16785. else
  16786. {
  16787. isSuccess = ConfigurationStatus_Rejected;
  16788. }
  16789. }
  16790. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16791. {
  16792. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16793. {
  16794. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16795. isSuccess = ConfigurationStatus_Accepted;
  16796. }
  16797. else
  16798. {
  16799. isSuccess = ConfigurationStatus_Rejected;
  16800. }
  16801. }
  16802. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16803. {
  16804. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16805. {
  16806. check_ascii = value[0];
  16807. if( (check_ascii < 48) || (check_ascii > 57) )
  16808. {
  16809. isSuccess = ConfigurationStatus_Rejected;
  16810. }
  16811. else
  16812. {
  16813. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16814. isSuccess = ConfigurationStatus_Accepted;
  16815. }
  16816. }
  16817. else
  16818. {
  16819. isSuccess = ConfigurationStatus_Rejected;
  16820. }
  16821. }
  16822. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16823. {
  16824. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16825. {
  16826. check_ascii = value[0];
  16827. if( (check_ascii < 48) || (check_ascii > 57) )
  16828. {
  16829. isSuccess = ConfigurationStatus_Rejected;
  16830. }
  16831. else
  16832. {
  16833. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16834. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16835. TransactionMessageAttemptsValue = atoi(value);
  16836. isSuccess = ConfigurationStatus_Accepted;
  16837. }
  16838. }
  16839. else
  16840. {
  16841. isSuccess = ConfigurationStatus_Rejected;
  16842. }
  16843. }
  16844. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16845. {
  16846. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16847. {
  16848. check_ascii = value[0];
  16849. if( (check_ascii < 48) || (check_ascii > 57) )
  16850. {
  16851. isSuccess = ConfigurationStatus_Rejected;
  16852. }
  16853. else
  16854. {
  16855. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16856. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16857. TransactionMessageRetryIntervalValue = atoi(value);
  16858. isSuccess = ConfigurationStatus_Accepted;
  16859. }
  16860. }
  16861. else
  16862. {
  16863. isSuccess = ConfigurationStatus_Rejected;
  16864. }
  16865. }
  16866. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16867. {
  16868. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16869. {
  16870. strcpy(str, (const char*)value);
  16871. for(int i = 0; str[i]; i++)
  16872. {
  16873. str[i] = tolower(str[i]);
  16874. }
  16875. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16876. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16877. isSuccess = ConfigurationStatus_Accepted;
  16878. }
  16879. else
  16880. {
  16881. isSuccess = ConfigurationStatus_Rejected;
  16882. }
  16883. }
  16884. if(strcmp(key, "WebSocketPingInterval") == 0)
  16885. {
  16886. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16887. {
  16888. check_ascii = value[0];
  16889. if( (check_ascii < 48) || (check_ascii > 57) )
  16890. {
  16891. isSuccess = ConfigurationStatus_Rejected;
  16892. }
  16893. else
  16894. {
  16895. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16896. isSuccess = ConfigurationStatus_Accepted;
  16897. if((atoi(value) == 0) || (atoi(value) >= 10))
  16898. {
  16899. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16900. isSuccess = ConfigurationStatus_Accepted;
  16901. }
  16902. else
  16903. isSuccess = ConfigurationStatus_Rejected;
  16904. }
  16905. }
  16906. else
  16907. {
  16908. isSuccess = ConfigurationStatus_Rejected;
  16909. }
  16910. }
  16911. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16912. {
  16913. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16914. {
  16915. strcpy(str, (const char*)value);
  16916. for(int i = 0; str[i]; i++)
  16917. {
  16918. str[i] = tolower(str[i]);
  16919. }
  16920. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16921. isSuccess = ConfigurationStatus_Accepted;
  16922. }
  16923. else
  16924. {
  16925. isSuccess = ConfigurationStatus_Rejected;
  16926. }
  16927. }
  16928. if(strcmp(key, "AuthorizationKey") == 0)
  16929. {
  16930. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16931. {
  16932. strcpy(str, (const char*)value);
  16933. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16934. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16935. isSuccess = ConfigurationStatus_Accepted;
  16936. }
  16937. else
  16938. {
  16939. isSuccess = ConfigurationStatus_Rejected;
  16940. }
  16941. }
  16942. if(strcmp(key, "SecurityProfile") == 0)
  16943. {
  16944. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16945. {
  16946. check_ascii = value[0];
  16947. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16948. {
  16949. isSuccess = ConfigurationStatus_Rejected;
  16950. }
  16951. else if(check_ascii == 0x33)
  16952. {
  16953. isSuccess = NotSupported;
  16954. }
  16955. else
  16956. {
  16957. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16958. {
  16959. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16960. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16961. isSuccess = ConfigurationStatus_Accepted;
  16962. }
  16963. else
  16964. isSuccess = ConfigurationStatus_Rejected;
  16965. }
  16966. }
  16967. else
  16968. {
  16969. isSuccess = ConfigurationStatus_Rejected;
  16970. }
  16971. }
  16972. if(strcmp(key, "DefaultPrice") == 0)
  16973. {
  16974. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16975. {
  16976. strcpy(str, (const char*)value);
  16977. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16978. isSuccess = ConfigurationStatus_Accepted;
  16979. }
  16980. else
  16981. {
  16982. isSuccess = ConfigurationStatus_Rejected;
  16983. }
  16984. }
  16985. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16986. {
  16987. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16988. {
  16989. strcpy(str, (const char*)value);
  16990. for(int i = 0; str[i]; i++)
  16991. {
  16992. str[i] = tolower(str[i]);
  16993. }
  16994. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16995. isSuccess = ConfigurationStatus_Accepted;
  16996. }
  16997. else
  16998. {
  16999. isSuccess = ConfigurationStatus_Rejected;
  17000. }
  17001. }
  17002. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  17003. {
  17004. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17005. {
  17006. strcpy(str, (const char*)value);
  17007. for(int i = 0; str[i]; i++)
  17008. {
  17009. str[i] = tolower(str[i]);
  17010. }
  17011. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17012. isSuccess = ConfigurationStatus_Accepted;
  17013. }
  17014. else
  17015. {
  17016. isSuccess = ConfigurationStatus_Rejected;
  17017. }
  17018. }
  17019. if(strcmp(key, "SystemUptimeSec") == 0)
  17020. {
  17021. isSuccess = NotSupported;
  17022. }
  17023. if(strcmp(key, "FreeVend") == 0)
  17024. {
  17025. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17026. {
  17027. strcpy(str, (const char*)value);
  17028. for(int i = 0; str[i]; i++)
  17029. {
  17030. str[i] = tolower(str[i]);
  17031. }
  17032. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17033. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17034. isSuccess = ConfigurationStatus_Accepted;
  17035. }
  17036. else
  17037. {
  17038. isSuccess = ConfigurationStatus_Rejected;
  17039. }
  17040. }
  17041. if(strcmp(key, "FreeVendIdtag") == 0)
  17042. {
  17043. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17044. {
  17045. strcpy(str, (const char*)value);
  17046. if(strlen(str) <= 20)
  17047. {
  17048. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17049. isSuccess = ConfigurationStatus_Accepted;
  17050. }
  17051. else
  17052. {
  17053. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17054. isSuccess = ConfigurationStatus_Rejected;
  17055. }
  17056. }
  17057. else
  17058. {
  17059. isSuccess = ConfigurationStatus_Rejected;
  17060. }
  17061. }
  17062. if(strcmp(key, "OcppServer") == 0)
  17063. {
  17064. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17065. {
  17066. strcpy(str, (const char*)value);
  17067. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17068. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17069. isSuccess = ConfigurationStatus_Accepted;
  17070. }
  17071. else
  17072. {
  17073. isSuccess = ConfigurationStatus_Rejected;
  17074. }
  17075. }
  17076. if(strcmp(key, "MaintainServer") == 0)
  17077. {
  17078. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17079. {
  17080. strcpy(str, (const char*)value);
  17081. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17082. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17083. isSuccess = ConfigurationStatus_Accepted;
  17084. }
  17085. else
  17086. {
  17087. isSuccess = ConfigurationStatus_Rejected;
  17088. }
  17089. }
  17090. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17091. {
  17092. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].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. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17100. isSuccess = ConfigurationStatus_Accepted;
  17101. }
  17102. else
  17103. {
  17104. isSuccess = ConfigurationStatus_Rejected;
  17105. }
  17106. }
  17107. if(strcmp(key, "StatusNotificationInterval") == 0)
  17108. {
  17109. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17110. {
  17111. check_ascii = value[0];
  17112. if( (check_ascii < 48) || (check_ascii > 57) )
  17113. {
  17114. isSuccess = ConfigurationStatus_Rejected;
  17115. }
  17116. else
  17117. {
  17118. if((atoi(value) == 0) || (atoi(value) >= 10))
  17119. {
  17120. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17121. isSuccess = ConfigurationStatus_Accepted;
  17122. }
  17123. else
  17124. isSuccess = ConfigurationStatus_Rejected;
  17125. }
  17126. }
  17127. else
  17128. {
  17129. isSuccess = ConfigurationStatus_Rejected;
  17130. }
  17131. }
  17132. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17133. {
  17134. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17135. {
  17136. check_ascii = value[0];
  17137. if( (check_ascii < 48) || (check_ascii > 57) )
  17138. {
  17139. isSuccess = ConfigurationStatus_Rejected;
  17140. }
  17141. else
  17142. {
  17143. if(atoi(value) >= 0)
  17144. {
  17145. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value) );
  17146. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17147. isSuccess = ConfigurationStatus_Accepted;
  17148. }
  17149. else
  17150. isSuccess = ConfigurationStatus_Rejected;
  17151. }
  17152. }
  17153. else
  17154. {
  17155. isSuccess = ConfigurationStatus_Rejected;
  17156. }
  17157. }
  17158. if(strcmp(key, "PowerSharingServerIP") == 0)
  17159. {
  17160. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17161. {
  17162. strcpy(str, (const char*)value);
  17163. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17164. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17165. isSuccess = ConfigurationStatus_Accepted;
  17166. }
  17167. else
  17168. {
  17169. isSuccess = ConfigurationStatus_Rejected;
  17170. }
  17171. }
  17172. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17173. {
  17174. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17175. {
  17176. strcpy(str, (const char*)value);
  17177. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17178. isSuccess = ConfigurationStatus_Accepted;
  17179. }
  17180. else
  17181. {
  17182. isSuccess = ConfigurationStatus_Rejected;
  17183. }
  17184. }
  17185. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  17186. {
  17187. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17188. {
  17189. if(atoi(value) > modelnameInfo.ratedPower)
  17190. {
  17191. isSuccess = ConfigurationStatus_Rejected;
  17192. }
  17193. else{
  17194. strcpy(str, (const char*)value);
  17195. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  17196. isSuccess = ConfigurationStatus_Accepted;
  17197. }
  17198. }
  17199. else
  17200. {
  17201. isSuccess = ConfigurationStatus_Rejected;
  17202. }
  17203. }
  17204. #if 0
  17205. //For OCPP Test Case
  17206. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17207. {
  17208. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17209. {
  17210. strcpy(str, (const char*)value);
  17211. for(int i = 0; str[i]; i++)
  17212. {
  17213. str[i] = tolower(str[i]);
  17214. }
  17215. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17216. isSuccess = ConfigurationStatus_Accepted;
  17217. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17218. }
  17219. else
  17220. {
  17221. isSuccess = ConfigurationStatus_Rejected;
  17222. }
  17223. }
  17224. #endif
  17225. #if 1
  17226. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17227. {
  17228. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17229. {
  17230. strcpy(str, (const char*)value);
  17231. for(int i = 0; str[i]; i++)
  17232. {
  17233. str[i] = tolower(str[i]);
  17234. }
  17235. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17236. isSuccess = ConfigurationStatus_Accepted;
  17237. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17238. }
  17239. else
  17240. {
  17241. isSuccess = ConfigurationStatus_Rejected;
  17242. }
  17243. }
  17244. #endif
  17245. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17246. {
  17247. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17248. {
  17249. check_ascii = value[0];
  17250. if( (check_ascii < 48) || (check_ascii > 57) )
  17251. {
  17252. isSuccess = ConfigurationStatus_Rejected;
  17253. }
  17254. else
  17255. {
  17256. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17257. isSuccess = ConfigurationStatus_Accepted;
  17258. }
  17259. }
  17260. else
  17261. {
  17262. isSuccess = ConfigurationStatus_Rejected;
  17263. }
  17264. }
  17265. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17266. {
  17267. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17268. {
  17269. check_ascii = value[0];
  17270. if( (check_ascii < 48) || (check_ascii > 57) )
  17271. {
  17272. isSuccess = ConfigurationStatus_Rejected;
  17273. }
  17274. else
  17275. {
  17276. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17277. isSuccess = ConfigurationStatus_Accepted;
  17278. }
  17279. }
  17280. else
  17281. {
  17282. isSuccess = ConfigurationStatus_Rejected;
  17283. }
  17284. }
  17285. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17286. {
  17287. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17288. {
  17289. strcpy(str, (const char*)value);
  17290. for(int i = 0; str[i]; i++)
  17291. {
  17292. str[i] = tolower(str[i]);
  17293. }
  17294. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17295. isSuccess = ConfigurationStatus_Accepted;
  17296. }
  17297. else
  17298. {
  17299. isSuccess = ConfigurationStatus_Rejected;
  17300. }
  17301. }
  17302. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17303. {
  17304. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17305. {
  17306. check_ascii = value[0];
  17307. if( (check_ascii < 48) || (check_ascii > 57) )
  17308. {
  17309. isSuccess = ConfigurationStatus_Rejected;
  17310. }
  17311. else
  17312. {
  17313. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17314. isSuccess = ConfigurationStatus_Accepted;
  17315. }
  17316. }
  17317. else
  17318. {
  17319. isSuccess = ConfigurationStatus_Rejected;
  17320. }
  17321. }
  17322. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17323. {
  17324. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17325. {
  17326. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17327. isSuccess = ConfigurationStatus_Accepted;
  17328. }
  17329. else
  17330. {
  17331. isSuccess = ConfigurationStatus_Rejected;
  17332. }
  17333. }
  17334. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17335. {
  17336. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17337. {
  17338. check_ascii = value[0];
  17339. if( (check_ascii < 48) || (check_ascii > 57) )
  17340. {
  17341. isSuccess = ConfigurationStatus_Rejected;
  17342. }
  17343. else
  17344. {
  17345. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17346. isSuccess = ConfigurationStatus_Accepted;
  17347. }
  17348. }
  17349. else
  17350. {
  17351. isSuccess = ConfigurationStatus_Rejected;
  17352. }
  17353. }
  17354. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17355. {
  17356. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17357. {
  17358. strcpy(str, (const char*)value);
  17359. for(int i = 0; str[i]; i++)
  17360. {
  17361. str[i] = tolower(str[i]);
  17362. }
  17363. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17364. isSuccess = ConfigurationStatus_Accepted;
  17365. }
  17366. else
  17367. {
  17368. isSuccess = ConfigurationStatus_Rejected;
  17369. }
  17370. }
  17371. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17372. {
  17373. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17374. {
  17375. check_ascii = value[0];
  17376. if( (check_ascii < 48) || (check_ascii > 57) )
  17377. {
  17378. isSuccess = ConfigurationStatus_Rejected;
  17379. }
  17380. else
  17381. {
  17382. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17383. isSuccess = ConfigurationStatus_Accepted;
  17384. }
  17385. }
  17386. else
  17387. {
  17388. isSuccess = ConfigurationStatus_Rejected;
  17389. }
  17390. }
  17391. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17392. return isSuccess;
  17393. }
  17394. int TransactionMessageAttemptsGet(void)
  17395. {
  17396. return TransactionMessageAttemptsValue;
  17397. }
  17398. int FirstHeartBeatResponse(void)
  17399. {
  17400. return FirstHeartBeat;
  17401. }
  17402. int TransactionMessageRetryIntervalGet(void)
  17403. {
  17404. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17405. }
  17406. int ReadHttpStatus(int sock)
  17407. {
  17408. //char c;
  17409. char buff[1024]="",*ptr=buff+1;
  17410. int bytes_received, status;
  17411. DEBUG_INFO("Begin Response ..\n");
  17412. while((bytes_received = recv(sock, ptr, 1, 0))){
  17413. if(bytes_received==-1){
  17414. perror("ReadHttpStatus");
  17415. exit(1);
  17416. }
  17417. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17418. ptr++;
  17419. }
  17420. *ptr=0;
  17421. ptr=buff+1;
  17422. sscanf(ptr,"%*s %d ", &status);
  17423. DEBUG_INFO("%s\n",ptr);
  17424. DEBUG_INFO("status=%d\n",status);
  17425. DEBUG_INFO("End Response ..\n");
  17426. return (bytes_received>0)?status:0;
  17427. }
  17428. //the only filed that it parsed is 'Content-Length'
  17429. int ParseHeader(int sock)
  17430. {
  17431. //char c;
  17432. char buff[1024]="",*ptr=buff+4;
  17433. int bytes_received;
  17434. DEBUG_INFO("Begin HEADER ..\n");
  17435. while((bytes_received = recv(sock, ptr, 1, 0))){
  17436. if(bytes_received==-1){
  17437. perror("Parse Header");
  17438. exit(1);
  17439. }
  17440. if(
  17441. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17442. (ptr[-1]=='\r') && (*ptr=='\n' )
  17443. ) break;
  17444. ptr++;
  17445. }
  17446. *ptr=0;
  17447. ptr=buff+4;
  17448. //printf("%s",ptr);
  17449. if(bytes_received){
  17450. ptr=strstr(ptr,"Content-Length:");
  17451. if(ptr){
  17452. sscanf(ptr,"%*s %d",&bytes_received);
  17453. }else
  17454. bytes_received=-1; //unknown size
  17455. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17456. }
  17457. DEBUG_INFO("End HEADER ..\n");
  17458. return bytes_received ;
  17459. }
  17460. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17461. {
  17462. int result = TRUE;
  17463. char rmFileCmd[100]={0};
  17464. char FilePath[100]={0};
  17465. char ftpbuf[200];
  17466. int systemresult;
  17467. sprintf(FilePath,"/mnt/%s",filename);
  17468. system("ping 8.8.8.8 &");
  17469. if((access(FilePath,F_OK))!=-1)
  17470. {
  17471. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17472. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17473. system(rmFileCmd);
  17474. }
  17475. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17476. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17477. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17478. systemresult = system(ftpbuf);
  17479. if(systemresult != 0)
  17480. {
  17481. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17482. result = FALSE;
  17483. }
  17484. system("pkill ping");
  17485. return result;
  17486. }
  17487. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  17488. {
  17489. int result = TRUE;
  17490. char rmFileCmd[100]={0};
  17491. char FilePath[100]={0};
  17492. char ftpbuf[200];
  17493. int systemresult;
  17494. sprintf(FilePath,"/mnt/%s",filename);
  17495. system("ping 8.8.8.8 &");
  17496. if((access(FilePath,F_OK))!=-1)
  17497. {
  17498. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17499. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17500. system(rmFileCmd);
  17501. }
  17502. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17503. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  17504. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17505. systemresult = system(ftpbuf);
  17506. if(systemresult != 0)
  17507. {
  17508. DEBUG_WARN("scp error!\n");
  17509. result = FALSE;
  17510. }
  17511. system("pkill ping");
  17512. return result;
  17513. }
  17514. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17515. {
  17516. int result = TRUE;
  17517. char rmFileCmd[100]={0};
  17518. char FilePath[100]={0};
  17519. char ftpbuf[200];
  17520. int systemresult;
  17521. sprintf(FilePath,"/mnt/%s",filename);
  17522. system("ping 8.8.8.8 &");
  17523. if((access(FilePath,F_OK))!=-1)
  17524. {
  17525. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17526. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17527. system(rmFileCmd);
  17528. }
  17529. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17530. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17531. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17532. systemresult = system(ftpbuf);
  17533. if(systemresult != 0)
  17534. {
  17535. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17536. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17537. systemresult = system(ftpbuf);
  17538. if(systemresult != 0)
  17539. {
  17540. DEBUG_WARN("FTP download fail!\n");
  17541. result = FALSE;
  17542. }
  17543. }
  17544. system("pkill ping");
  17545. return result;
  17546. }
  17547. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17548. {
  17549. char rmFileCmd[100]={0};
  17550. char FilePath[100]={0};
  17551. char buf[512];
  17552. int systemresult = 0;
  17553. //DEBUG_INFO("filename=%s\n",filename);
  17554. //DEBUG_INFO("url=%s\n",url);
  17555. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17556. if((access(FilePath,F_OK))!=-1)
  17557. {
  17558. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17559. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17560. system(rmFileCmd);
  17561. }
  17562. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17563. if(fp == NULL)
  17564. {
  17565. DEBUG_INFO("log is NULL\n");
  17566. return FALSE;
  17567. }
  17568. else
  17569. {
  17570. fprintf(fp, "%s\n", url);
  17571. fprintf(fp, "%s\n", filename);
  17572. fclose(fp);
  17573. }
  17574. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17575. if(phpFP == NULL)
  17576. {
  17577. DEBUG_INFO("PHP upload fail.\n");
  17578. return FALSE;
  17579. }
  17580. else
  17581. {
  17582. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17583. {
  17584. if(strstr(buf, "result") != NULL)
  17585. {
  17586. sscanf(buf, "result: %d", &systemresult);
  17587. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17588. }
  17589. }
  17590. pclose(phpFP);
  17591. }
  17592. if(systemresult != 1)
  17593. {
  17594. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17595. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17596. if(phpFP == NULL)
  17597. {
  17598. DEBUG_WARN("PHP PUT upload fail.\n");
  17599. return FALSE;
  17600. }
  17601. else
  17602. {
  17603. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17604. {
  17605. if(strstr(buf, "result") != NULL)
  17606. {
  17607. sscanf(buf, "result: %d", &systemresult);
  17608. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17609. }
  17610. }
  17611. pclose(phpFP);
  17612. }
  17613. }
  17614. if(systemresult != 1)
  17615. {
  17616. DEBUG_WARN("PHP PUT upload fail.\n");
  17617. return FALSE;
  17618. }
  17619. return TRUE;
  17620. }
  17621. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17622. {
  17623. int result = FALSE;
  17624. char ftpbuf[200];
  17625. int systemresult;
  17626. /*
  17627. // Domaind name transfer to IP address
  17628. struct hostent* server;
  17629. char *IPbuffer;
  17630. server = gethostbyname(location);
  17631. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17632. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17633. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17634. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17635. systemresult = system(ftpbuf);
  17636. if(systemresult != 0)
  17637. {
  17638. DEBUG_INFO("ftpput error!\n");
  17639. }
  17640. else
  17641. {
  17642. result = TRUE;
  17643. DEBUG_INFO("ftpput OK!\n");
  17644. }
  17645. return result;
  17646. }
  17647. int GetOcppServerURL()
  17648. {
  17649. int result = FALSE;
  17650. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17651. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17652. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17653. struct yuarel url;
  17654. char urlStr[512];
  17655. // OCPPPH only
  17656. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  17657. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  17658. {
  17659. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  17660. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17661. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17662. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  17663. if(yuarel_parse(&url, urlStr) != -1)
  17664. {
  17665. sprintf(OcppProtocol, "%s", url.scheme);
  17666. sprintf(OcppHost, "%s", url.host);
  17667. if(url.path == NULL)
  17668. OcppTempPath[0] = '\0';
  17669. else
  17670. sprintf(OcppTempPath, "%s", url.path);
  17671. if(url.port == 0)
  17672. {
  17673. if(strcmp(OcppProtocol, "wss") == 0)
  17674. OcppPort = 443;
  17675. else
  17676. OcppPort = 80;
  17677. }
  17678. else
  17679. OcppPort = url.port;
  17680. result = TRUE;
  17681. }
  17682. }
  17683. else
  17684. {
  17685. strcpy(OcppHost,"");
  17686. }
  17687. return result;
  17688. }
  17689. int GetOcppPath()
  17690. {
  17691. int result = FALSE;
  17692. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  17693. {
  17694. if(OcppTempPath == NULL)
  17695. {
  17696. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  17697. }
  17698. else
  17699. {
  17700. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  17701. }
  17702. result = TRUE;
  17703. goto End;
  17704. }
  17705. else
  17706. {
  17707. strcpy(OcppPath,"");
  17708. }
  17709. End:
  17710. return result;
  17711. }
  17712. int GetOcppPort()
  17713. {
  17714. return OcppPort;
  17715. }
  17716. int GetOcppConnStatus(void)
  17717. {
  17718. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17719. }
  17720. void SetOcppConnStatus(uint8_t status)
  17721. {
  17722. ShmOCPP16DataPH->OcppConnStatus = status;
  17723. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17724. }
  17725. int GetHeartBeatWithNOResponse(void)
  17726. {
  17727. return HeartBeatWithNOResponse;
  17728. }
  17729. void SetHeartBeatWithNOResponse(void)
  17730. {
  17731. HeartBeatWithNOResponse = 0;
  17732. }
  17733. void GetStartTransactionIdTag(int gun_index)
  17734. {
  17735. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17736. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17737. }
  17738. int GetStartTransactionId(int gun_index)
  17739. {
  17740. return ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17741. }
  17742. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17743. {
  17744. char ch;
  17745. FILE *fptr1;
  17746. int temptransactionId;
  17747. char str[100]={0};
  17748. temptransactionId = 0;
  17749. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17750. {
  17751. DEBUG_INFO("IdTag is empty.\n");
  17752. return temptransactionId;
  17753. }
  17754. /*------ Read the file ----------------*/
  17755. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17756. if (!fptr1)
  17757. {
  17758. DEBUG_INFO("QueueTransactionId file open error.\n");
  17759. //printf(" File not found or unable to open the input file!!\n");
  17760. return temptransactionId;
  17761. }
  17762. ch=fgetc(fptr1);
  17763. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17764. rewind(fptr1);
  17765. if(ch!=EOF)
  17766. {
  17767. // printf("%c",ch);
  17768. while (fgets(str, 100, fptr1) != NULL)
  17769. {
  17770. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17771. if(str[0]=='\0')
  17772. {
  17773. break;
  17774. }
  17775. char *revbuf[8] = {0}; // Variable store string split
  17776. int num = 0;// Quantity after string split
  17777. DEBUG_INFO("Transaction queue data= %s\n", str);
  17778. splitstring(str,",",revbuf,&num); // String split
  17779. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17780. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17781. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17782. DEBUG_INFO("------------------------------\n");
  17783. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17784. {
  17785. if(isStopTransaction)
  17786. {
  17787. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17788. {
  17789. temptransactionId = atoi(revbuf[2]);
  17790. //break;
  17791. }
  17792. }
  17793. else
  17794. {
  17795. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17796. {
  17797. temptransactionId = atoi(revbuf[2]);
  17798. //break;
  17799. }
  17800. }
  17801. }
  17802. }
  17803. }
  17804. else
  17805. DEBUG_INFO("EOF\n");
  17806. fclose(fptr1);
  17807. /*------- End of reading ---------------*/
  17808. return temptransactionId;
  17809. }
  17810. void SetTransactionIdZero(int transactionId)
  17811. {
  17812. char ch;
  17813. FILE *fptr1, *fptr2;
  17814. int temptransactionId = 0;
  17815. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17816. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17817. if (!fptr1)
  17818. {
  17819. //printf(" File not found or unable to open the input file!!\n");
  17820. return ;
  17821. }
  17822. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17823. if (!fptr2)
  17824. {
  17825. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17826. fclose(fptr1);
  17827. return ;
  17828. }
  17829. ch=fgetc(fptr1);
  17830. rewind(fptr1);
  17831. if(ch!=EOF)
  17832. {
  17833. // copy all contents to the temporary file except the specific line
  17834. while (fgets(str, 100, fptr1) != NULL)
  17835. {
  17836. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17837. if(str[0]=='\0')
  17838. {
  17839. break;
  17840. }
  17841. char *revbuf[8] = {0};
  17842. int num = 0;
  17843. strcpy(strtemp, str);
  17844. splitstring(str,",",revbuf,&num);
  17845. if(revbuf[2][0] != '\0')
  17846. {
  17847. temptransactionId = atoi(revbuf[2]);
  17848. if(transactionId != temptransactionId)
  17849. {
  17850. fprintf(fptr2, "%s\n", strtemp);
  17851. }
  17852. }
  17853. }
  17854. }
  17855. fclose(fptr1);
  17856. fclose(fptr2);
  17857. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17858. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17859. /*------ Read the file ----------------*/
  17860. }
  17861. int InternetDisconnect(void)
  17862. {
  17863. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17864. }
  17865. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17866. void storeTempStopTransaction(int gun_index)
  17867. {
  17868. char guid[37]={0};
  17869. int tempIndex = 0;
  17870. char TempStopTransaction[256];
  17871. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17872. DEBUG_INFO("storeTempStopTransaction...\n");
  17873. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17874. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17875. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17876. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17877. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17878. {
  17879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17880. {
  17881. tempIndex = ((gun_index==2) ? 1: 0);
  17882. }
  17883. else
  17884. {
  17885. tempIndex = gun_index;
  17886. }
  17887. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17888. {
  17889. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17890. {
  17891. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17892. }
  17893. }// END OF CHAdeMO_QUANTITY
  17894. }
  17895. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17896. {
  17897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17898. {
  17899. tempIndex = ((gun_index==2) ? 1: 0);
  17900. }
  17901. else
  17902. {
  17903. tempIndex = gun_index;
  17904. }
  17905. for (int index = 0; index < CCS_QUANTITY; index++)
  17906. {
  17907. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17908. {
  17909. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17910. }
  17911. }// END OF CCS_QUANTITY
  17912. }
  17913. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17914. {
  17915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17916. {
  17917. tempIndex = ((gun_index==2) ? 1: 0);
  17918. }
  17919. else
  17920. {
  17921. tempIndex = gun_index;
  17922. }
  17923. for (int index = 0; index < GB_QUANTITY; index++)
  17924. {
  17925. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17926. {
  17927. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17928. }
  17929. }// END OF GB_QUANTITY
  17930. }
  17931. else if(gunType[gun_index] == GUN_TYPE_DO)
  17932. {
  17933. tempIndex = gun_index;
  17934. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17935. {
  17936. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17937. {
  17938. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17939. }
  17940. }
  17941. }
  17942. else
  17943. {
  17944. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17945. {
  17946. tempIndex = 2;
  17947. }
  17948. else
  17949. {
  17950. tempIndex = gun_index;
  17951. }
  17952. for (int index = 0; index < AC_QUANTITY; index++)
  17953. {
  17954. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17955. {
  17956. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17957. }
  17958. }// END OF AC_QUANTITY
  17959. }
  17960. //Stop Transaction Time
  17961. struct timeval tmnow;
  17962. struct tm *tm;
  17963. char buf[28];//, usec_buf[6];
  17964. gettimeofday(&tmnow, NULL);
  17965. time_t t;
  17966. t = time(NULL);
  17967. /*UTC time and date*/
  17968. tm = gmtime(&t);
  17969. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17971. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17972. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17973. random_uuid(guid);
  17974. /***********************************transactionData******************************************************/
  17975. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17976. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17977. //=================================
  17978. //1. Transaction_Begin
  17979. //=================================
  17980. //============================== Energy.Active.Import.Interval ===========================================
  17981. //=================================
  17982. //2. Transaction_End
  17983. //=================================
  17984. //2.1====================================== Current.Import L1 ==============================================
  17985. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17986. {
  17987. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17988. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17989. {
  17990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17991. {
  17992. tempIndex = ((gun_index==2) ? 1: 0);
  17993. }
  17994. else
  17995. {
  17996. tempIndex = gun_index;
  17997. }
  17998. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17999. {
  18000. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18001. {
  18002. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18003. }
  18004. }// End of for CHAdeMO_QUANTITY
  18005. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18006. }
  18007. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18008. {
  18009. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18010. {
  18011. tempIndex = ((gun_index==2) ? 1: 0);
  18012. }
  18013. else
  18014. {
  18015. tempIndex = gun_index;
  18016. }
  18017. for (int index = 0; index < CCS_QUANTITY; index++)
  18018. {
  18019. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18020. {
  18021. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18022. }
  18023. }// End of for CCS_QUANTITY
  18024. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18025. }
  18026. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18027. {
  18028. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18029. {
  18030. tempIndex = ((gun_index==2) ? 1: 0);
  18031. }
  18032. else
  18033. {
  18034. tempIndex = gun_index;
  18035. }
  18036. for (int index = 0; index < GB_QUANTITY; index++)
  18037. {
  18038. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18039. {
  18040. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18041. }
  18042. }// End of for GB_QUANTITY
  18043. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18044. }
  18045. else if(gunType[gun_index] == GUN_TYPE_DO)
  18046. {
  18047. tempIndex = gun_index;
  18048. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18049. {
  18050. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18051. {
  18052. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18053. }
  18054. }
  18055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18056. }
  18057. else
  18058. {
  18059. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18060. {
  18061. tempIndex = 2;
  18062. }
  18063. else
  18064. {
  18065. tempIndex = gun_index;
  18066. }
  18067. for (int index = 0; index < AC_QUANTITY; index++)
  18068. {
  18069. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18070. {
  18071. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18072. }
  18073. }// End of for AC_QUANTITY
  18074. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18075. }
  18076. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18077. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18078. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18079. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18080. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18081. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18082. }
  18083. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18084. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18085. {
  18086. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18087. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18088. {
  18089. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18090. {
  18091. tempIndex = ((gun_index==2) ? 1: 0);
  18092. }
  18093. else
  18094. {
  18095. tempIndex = gun_index;
  18096. }
  18097. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18098. {
  18099. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18100. {
  18101. 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
  18102. }
  18103. }// END OF CHAdeMO_QUANTITY
  18104. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18105. }
  18106. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18107. {
  18108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18109. {
  18110. tempIndex = ((gun_index==2) ? 1: 0);
  18111. }
  18112. else
  18113. {
  18114. tempIndex = gun_index;
  18115. }
  18116. for (int index = 0; index < CCS_QUANTITY; index++)
  18117. {
  18118. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18119. {
  18120. 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
  18121. }
  18122. }// END OF CCS_QUANTITY
  18123. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18124. }
  18125. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18126. {
  18127. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18128. {
  18129. tempIndex = ((gun_index==2) ? 1: 0);
  18130. }
  18131. else
  18132. {
  18133. tempIndex = gun_index;
  18134. }
  18135. for (int index = 0; index < GB_QUANTITY; index++)
  18136. {
  18137. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18138. {
  18139. 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
  18140. }
  18141. }// END OF GB_QUANTITY
  18142. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18143. }
  18144. else if(gunType[gun_index] == GUN_TYPE_DO)
  18145. {
  18146. tempIndex = gun_index;
  18147. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18148. {
  18149. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18150. {
  18151. 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
  18152. }
  18153. }
  18154. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18155. }
  18156. else
  18157. {
  18158. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18159. {
  18160. tempIndex = 2;
  18161. }
  18162. else
  18163. {
  18164. tempIndex = gun_index;
  18165. }
  18166. for (int index = 0; index < AC_QUANTITY; index++)
  18167. {
  18168. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18169. {
  18170. 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
  18171. }
  18172. }// END OF AC_QUANTITY
  18173. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18174. }
  18175. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18176. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18177. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18178. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18179. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18180. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18181. }
  18182. //2.3====================================== Power.Active.Import =========================================
  18183. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18184. {
  18185. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18186. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18187. {
  18188. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18189. {
  18190. tempIndex = ((gun_index==2) ? 1: 0);
  18191. }
  18192. else
  18193. {
  18194. tempIndex = gun_index;
  18195. }
  18196. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18197. {
  18198. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18199. {
  18200. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18201. }
  18202. } // End for CHAdeMO_QUANTITY
  18203. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18204. }
  18205. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18206. {
  18207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18208. {
  18209. tempIndex = ((gun_index==2) ? 1: 0);
  18210. }
  18211. else
  18212. {
  18213. tempIndex = gun_index;
  18214. }
  18215. for (int index = 0; index < CCS_QUANTITY; index++)
  18216. {
  18217. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18218. {
  18219. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18220. }
  18221. } // END for CCS_QUANTITY
  18222. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18223. }
  18224. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18225. {
  18226. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18227. {
  18228. tempIndex = ((gun_index==2) ? 1: 0);
  18229. }
  18230. else
  18231. {
  18232. tempIndex = gun_index;
  18233. }
  18234. for (int index = 0; index < GB_QUANTITY; index++)
  18235. {
  18236. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18237. {
  18238. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18239. }
  18240. }// END for GB_QUANTITY
  18241. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18242. }
  18243. else if(gunType[gun_index] == GUN_TYPE_DO)
  18244. {
  18245. tempIndex = gun_index;
  18246. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18247. {
  18248. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18249. {
  18250. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18251. }
  18252. }
  18253. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18254. }
  18255. else
  18256. {
  18257. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18258. {
  18259. tempIndex = 2;
  18260. }
  18261. else
  18262. {
  18263. tempIndex = gun_index;
  18264. }
  18265. for (int index = 0; index < AC_QUANTITY; index++)
  18266. {
  18267. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18268. {
  18269. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18270. }
  18271. } // END for AC_QUANTITY
  18272. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18273. }
  18274. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18277. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18278. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18280. }
  18281. //2.4====================================== Voltage L1 ====================================================
  18282. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18283. {
  18284. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18285. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18286. {
  18287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18288. {
  18289. tempIndex = ((gun_index==2) ? 1: 0);
  18290. }
  18291. else
  18292. {
  18293. tempIndex = gun_index;
  18294. }
  18295. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18296. {
  18297. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18298. {
  18299. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18300. }
  18301. } // END OF FOR CHAdeMO_QUANTITY
  18302. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18303. }
  18304. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18305. {
  18306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18307. {
  18308. tempIndex = ((gun_index==2) ? 1: 0);
  18309. }
  18310. else
  18311. {
  18312. tempIndex = gun_index;
  18313. }
  18314. for (int index = 0; index < CCS_QUANTITY; index++)
  18315. {
  18316. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18317. {
  18318. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18319. }
  18320. } // END OF FOR CCS_QUANTITY
  18321. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18322. }
  18323. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18324. {
  18325. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18326. {
  18327. tempIndex = ((gun_index==2) ? 1: 0);
  18328. }
  18329. else
  18330. {
  18331. tempIndex = gun_index;
  18332. }
  18333. for (int index = 0; index < GB_QUANTITY; index++)
  18334. {
  18335. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18336. {
  18337. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18338. }
  18339. } // END OF FOR GB_QUANTITY
  18340. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18341. }
  18342. else if(gunType[gun_index] == GUN_TYPE_DO)
  18343. {
  18344. tempIndex = gun_index;
  18345. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18346. {
  18347. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18348. {
  18349. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18350. }
  18351. }
  18352. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18353. }
  18354. else
  18355. {
  18356. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18357. {
  18358. tempIndex = 2;
  18359. }
  18360. else
  18361. {
  18362. tempIndex = gun_index;
  18363. }
  18364. for (int index = 0; index < AC_QUANTITY; index++)
  18365. {
  18366. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18367. {
  18368. 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
  18369. }
  18370. } // END OF FOR AC_QUANTITY
  18371. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18372. }
  18373. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18374. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18375. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18376. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18377. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18378. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18379. }
  18380. //2.5============================================== End SoC =========================================================
  18381. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18382. {
  18383. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18384. 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))
  18385. {
  18386. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18387. {
  18388. tempIndex = ((gun_index==2) ? 1: 0);
  18389. }
  18390. else
  18391. {
  18392. tempIndex = gun_index;
  18393. }
  18394. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18395. {
  18396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18397. {
  18398. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18399. {
  18400. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18401. }
  18402. }
  18403. }
  18404. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18405. {
  18406. for (int index = 0; index < CCS_QUANTITY; index++)
  18407. {
  18408. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18409. {
  18410. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18411. }
  18412. }
  18413. }
  18414. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18415. {
  18416. for (int index = 0; index < GB_QUANTITY; index++)
  18417. {
  18418. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18419. {
  18420. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18421. }
  18422. }
  18423. }
  18424. else if(gunType[gun_index] == GUN_TYPE_DO)
  18425. {
  18426. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18427. {
  18428. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18429. {
  18430. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18431. }
  18432. }
  18433. }
  18434. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18435. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18436. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18437. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18438. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18439. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18440. } // END FOR DC CASE
  18441. }
  18442. //2.6====================================== Current.Import L2 ==============================================
  18443. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18444. {
  18445. // AC 3 phase L2 current
  18446. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18447. {
  18448. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18449. {
  18450. tempIndex = 2;
  18451. }
  18452. else
  18453. {
  18454. tempIndex = gun_index;
  18455. }
  18456. for (int index = 0; index < AC_QUANTITY; index++)
  18457. {
  18458. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18459. {
  18460. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18461. }
  18462. }// End of for AC_QUANTITY
  18463. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18464. }
  18465. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18466. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18467. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18468. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18469. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18470. }
  18471. //2.7====================================== Current.Import L3 ==============================================
  18472. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18473. {
  18474. // AC 3 phase L3 current
  18475. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18476. {
  18477. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18478. {
  18479. tempIndex = 2;
  18480. }
  18481. else
  18482. {
  18483. tempIndex = gun_index;
  18484. }
  18485. for (int index = 0; index < AC_QUANTITY; index++)
  18486. {
  18487. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18488. {
  18489. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18490. }
  18491. }// End of for AC_QUANTITY
  18492. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18493. }
  18494. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18495. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18496. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18497. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18498. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18499. }
  18500. //2.9====================================== Voltage L2 ====================================================
  18501. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18502. {
  18503. // AC 3 phase L2 volatge
  18504. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18505. {
  18506. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18507. {
  18508. tempIndex = 2;
  18509. }
  18510. else
  18511. {
  18512. tempIndex = gun_index;
  18513. }
  18514. for (int index = 0; index < AC_QUANTITY; index++)
  18515. {
  18516. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18517. {
  18518. 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
  18519. }
  18520. } // END OF FOR AC_QUANTITY
  18521. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18522. }
  18523. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18524. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18525. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18526. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18527. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18528. }
  18529. //2.10====================================== Voltage L3 ====================================================
  18530. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18531. {
  18532. // AC 3 phase L3 volatge
  18533. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18534. {
  18535. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18536. {
  18537. tempIndex = 2;
  18538. }
  18539. else
  18540. {
  18541. tempIndex = gun_index;
  18542. }
  18543. for (int index = 0; index < AC_QUANTITY; index++)
  18544. {
  18545. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18546. {
  18547. 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
  18548. }
  18549. } // END OF FOR AC_QUANTITY
  18550. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18551. }
  18552. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18553. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18554. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18555. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18556. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18557. }
  18558. //====================== Start SoC ================================
  18559. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18560. {
  18561. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18562. 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))
  18563. {
  18564. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18565. {
  18566. tempIndex = ((gun_index==2) ? 1: 0);
  18567. }
  18568. else
  18569. {
  18570. tempIndex = gun_index;
  18571. }
  18572. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18573. {
  18574. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18575. {
  18576. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18577. {
  18578. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18579. }
  18580. }
  18581. }
  18582. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18583. {
  18584. for (int index = 0; index < CCS_QUANTITY; index++)
  18585. {
  18586. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18587. {
  18588. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18589. }
  18590. }
  18591. }
  18592. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18593. {
  18594. for (int index = 0; index < GB_QUANTITY; index++)
  18595. {
  18596. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18597. {
  18598. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18599. }
  18600. }
  18601. }
  18602. else if(gunType[gun_index] == GUN_TYPE_DO)
  18603. {
  18604. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18605. {
  18606. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18607. {
  18608. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18609. }
  18610. }
  18611. }
  18612. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18613. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18614. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18615. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18616. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18617. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18618. } // END FOR DC CASE
  18619. }
  18620. //======================================== Message create ==============================================
  18621. json_object *StopTransaction = json_object_new_object();
  18622. json_object *transactionDatas = json_object_new_array();
  18623. json_object *sampledValues = json_object_new_array();
  18624. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  18625. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  18626. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  18627. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  18628. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  18629. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18630. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  18631. {
  18632. json_object *transactionData = json_object_new_object();
  18633. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18634. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18635. {
  18636. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18637. {
  18638. json_object *sampledValue = json_object_new_object();
  18639. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18640. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18641. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18642. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18643. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18644. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18645. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18646. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18647. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18648. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18649. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18650. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18651. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18652. json_object_array_add(sampledValues, sampledValue);
  18653. }
  18654. }
  18655. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18656. json_object_array_add(transactionDatas, transactionData);
  18657. }
  18658. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18659. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18660. ,MESSAGE_TYPE_CALL
  18661. ,guid
  18662. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18663. json_object_put(StopTransaction);
  18664. // Check File "TempStopTransaction" Exist
  18665. if((access(TempStopTransaction,F_OK))!=-1)
  18666. {
  18667. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18668. fclose(fopen(TempStopTransaction, "w"));
  18669. }
  18670. else
  18671. {
  18672. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18673. FILE *log = fopen(TempStopTransaction, "w+");
  18674. if(log == NULL)
  18675. {
  18676. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18677. return ;
  18678. }
  18679. else
  18680. {
  18681. fclose(log);
  18682. }
  18683. }
  18684. //Add TempStopTransaction | Update TempStopTransaction
  18685. // open file for writing
  18686. FILE *outfile;
  18687. outfile = fopen (TempStopTransaction, "a");
  18688. //DEBUG_INFO("data = %s\n", queuedata);
  18689. fputs(queuedata, outfile);
  18690. fputs("\n", outfile);
  18691. fclose (outfile);
  18692. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18693. }
  18694. void checkTempStopTransaction(int gun_index)
  18695. {
  18696. FILE *fptr1;
  18697. char ch;
  18698. char str[QUEUE_MESSAGE_LENGTH]={0};
  18699. char guid[37]={0};
  18700. char tempdata[65]={0};
  18701. char connectorStr[2]={0};
  18702. char TempStopTransaction[256];
  18703. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18704. fptr1 = fopen(TempStopTransaction, "r");
  18705. //TempStopTransaction格式: 槍號,StopTransaction封包
  18706. if (!fptr1)
  18707. {
  18708. //printf(" File not found or unable to open the input file!!\n");
  18709. return ;
  18710. }
  18711. ch=fgetc(fptr1);
  18712. //printf(" Now the content of the file %s is : \n",fname);
  18713. rewind(fptr1);
  18714. if(ch!=EOF)
  18715. {
  18716. // copy all contents to the temporary file except the specific line
  18717. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18718. {
  18719. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18720. if(str[0]=='\0')
  18721. {
  18722. break;
  18723. }
  18724. //TempStopTransaction格式: 槍號,StopTransaction封包
  18725. strncpy(connectorStr, str, 1);
  18726. if(atoi(connectorStr) != (gun_index+1))
  18727. {
  18728. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18729. fclose(fptr1);
  18730. return ;
  18731. }
  18732. //random_uuid(guid);
  18733. strncpy(guid, str+6, 36); //copy guid
  18734. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18735. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18736. {
  18737. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18738. }
  18739. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18740. OCPP_insert_transaction_msg(NO, str);
  18741. memset(str,0,ARRAY_SIZE(str));
  18742. }
  18743. }
  18744. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18745. fclose(fptr1);
  18746. remove(TempStopTransaction); // remove the original file
  18747. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18748. }
  18749. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18750. {
  18751. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18752. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18753. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18754. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18755. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18756. }
  18757. int GetWebSocketPingInterval(void)
  18758. {
  18759. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18760. }
  18761. int GetServerSign(void)
  18762. {
  18763. return server_sign;
  18764. }
  18765. uint8_t GetOcppSecurityProfile()
  18766. {
  18767. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18768. }
  18769. void GetOcppChargerBoxId(uint8_t *data)
  18770. {
  18771. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18772. }
  18773. void GetOcppSecurityPassword(uint8_t *data)
  18774. {
  18775. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18776. }
  18777. void SetOcppVersion(uint8_t *version)
  18778. {
  18779. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18780. DEBUG_INFO("ocpp version: %s\n", version);
  18781. if(strstr((char*)version, "ocpp1.6") != NULL)
  18782. {
  18783. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18784. }
  18785. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18786. {
  18787. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18788. system("pkill OcppBackend");
  18789. }
  18790. }
  18791. void SetServerSign(int value)
  18792. {
  18793. server_sign = value;
  18794. }
  18795. int GetBootNotificationInterval(void)
  18796. {
  18797. return BootNotificationInterval;
  18798. }
  18799. int GetInternetConn(void)
  18800. {
  18801. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18802. }
  18803. int GetBackendConnectionTimeout(void)
  18804. {
  18805. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18806. }
  18807. int isConnectorInitMode(int gun_index)
  18808. {
  18809. int tempIndex = 0;
  18810. int result = TRUE;
  18811. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18812. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18813. {
  18814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18815. {
  18816. tempIndex = ((gun_index==2) ? 1: 0);
  18817. }
  18818. else
  18819. {
  18820. tempIndex = gun_index;
  18821. }
  18822. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18823. {
  18824. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18825. {
  18826. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18827. } //end of the same index
  18828. }//end of for CHAdeMO_QUANTITY
  18829. }
  18830. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18831. {
  18832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18833. {
  18834. tempIndex = ((gun_index==2) ? 1: 0);
  18835. }
  18836. else
  18837. {
  18838. tempIndex = gun_index;
  18839. }
  18840. for (int index = 0; index < CCS_QUANTITY; index++)
  18841. {
  18842. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18843. {
  18844. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18845. } //end of the same index
  18846. } // end of for CCS_QUANTITY
  18847. }
  18848. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18849. {
  18850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18851. {
  18852. tempIndex = ((gun_index==2) ? 1: 0);
  18853. }
  18854. else
  18855. {
  18856. tempIndex = gun_index;
  18857. }
  18858. for (int index = 0; index < GB_QUANTITY; index++)
  18859. {
  18860. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18861. {
  18862. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18863. } //end of the same index
  18864. } // end of for GB_QUANTITY
  18865. }
  18866. else if(gunType[gun_index] == GUN_TYPE_DO)
  18867. {
  18868. tempIndex = gun_index;
  18869. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18870. {
  18871. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18872. {
  18873. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18874. } //end of the same index
  18875. }
  18876. }
  18877. else
  18878. {
  18879. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18880. {
  18881. tempIndex = 2;
  18882. }
  18883. else
  18884. {
  18885. tempIndex = gun_index;
  18886. }
  18887. for (int index = 0; index < AC_QUANTITY; index++)
  18888. {
  18889. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18890. {
  18891. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18892. }//end of the same index
  18893. }//end of for AC_QUANTITY
  18894. }
  18895. return result;
  18896. }
  18897. void refreshProcDogTimer()
  18898. {
  18899. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18900. }
  18901. void InitialSystemValue(void)
  18902. {
  18903. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18904. locallistVersion=0;
  18905. BootNotificationInterval = 0;
  18906. authorizeRetryTimes = 0;
  18907. GunStatusInterval = 10;
  18908. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18909. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18910. //Hear Beat
  18911. HeartBeatWithNOResponse = 0;
  18912. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18913. FirstHeartBeat = 0;
  18914. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18915. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18916. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18917. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18918. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18919. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18920. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18921. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18922. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18923. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18924. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18925. //Status && ConnectorPlugIn Setting
  18926. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18927. {
  18928. ChademoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18929. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18930. }
  18931. for (int index = 0; index < CCS_QUANTITY; index++)
  18932. {
  18933. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18934. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18935. }
  18936. for (int index = 0; index < GB_QUANTITY; index++)
  18937. {
  18938. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18939. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18940. }
  18941. for (int index = 0; index < AC_QUANTITY; index++)
  18942. {
  18943. AcPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18944. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18945. }
  18946. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18947. {
  18948. DoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18949. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18950. }
  18951. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18952. {
  18953. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18954. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18955. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18956. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18957. //memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18958. memset(&ShmOCPP16DataPH->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16DataPH->StatusNotification[gun_index].Status));
  18959. }
  18960. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18961. refreshStartTimer(&clientTime.Heartbeat);
  18962. sleep(1);
  18963. }
  18964. void LWS_Send(char *str)
  18965. {
  18966. //=====================================================
  18967. // Check InternetConn 0: disconnected, 1: connected
  18968. //====================================================
  18969. if(GetOcppConnStatus() == 0)
  18970. {
  18971. DEBUG_INFO("offline now !!!\n");
  18972. return;
  18973. }
  18974. // Only disable isWebsocketSendable operation initiated by charger
  18975. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18976. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18977. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18978. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18979. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18980. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18981. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18982. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18983. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18984. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18985. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18986. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18987. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18988. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18989. {
  18990. isWebsocketSendable = 0;
  18991. }
  18992. pthread_mutex_lock(&lock_send);
  18993. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18994. sprintf((char *)SendBuffer, "%s", str);
  18995. SendBufLen = strlen(str);
  18996. pthread_mutex_unlock(&lock_send);
  18997. lws_callback_on_writable(wsi_client);
  18998. //lws_service(context, 0);
  18999. //sleep(1);
  19000. }
  19001. void LWS_SendNow(char *str)
  19002. {
  19003. //=====================================================
  19004. // Check InternetConn 0: disconnected, 1: connected
  19005. //====================================================
  19006. if(GetOcppConnStatus() == 0)
  19007. {
  19008. DEBUG_INFO("offline now !!!\n");
  19009. return;
  19010. }
  19011. // Only disable isWebsocketSendable operation initiated by charger
  19012. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19013. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19014. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19015. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19016. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19017. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19018. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19019. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19020. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19021. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19022. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19023. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19024. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19025. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19026. {
  19027. isWebsocketSendable = 0;
  19028. }
  19029. pthread_mutex_lock(&lock_send);
  19030. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19031. sprintf((char *)SendBuffer, "%s", str);
  19032. SendBufLen = strlen(str);
  19033. pthread_mutex_unlock(&lock_send);
  19034. lws_callback_on_writable(wsi_client);
  19035. lws_service(context, 0);
  19036. //sleep(1);
  19037. }