MessageHandler.c 940 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  56. //========================================
  57. // OCPP status/previous related variables
  58. //========================================
  59. static int GunStatusInterval = 10;
  60. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  61. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  62. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  63. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  64. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  65. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  66. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  67. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  68. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  69. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  70. static int TransactionMessageAttemptsValue = 0;
  71. static int TransactionMessageRetryIntervalValue = 0;
  72. static int TempMeterValueInterval = 0;
  73. static struct OCPPAuthLocalElemet
  74. {
  75. int listVersionInt;
  76. char idTagstr[21];
  77. char parentIdTag[21];
  78. char expiryDate[36];
  79. char idTagstatus[16];
  80. }idTagQuery;
  81. //============================================
  82. // OCPP MeterValue request flag
  83. //============================================
  84. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  85. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  86. //============================================
  87. // OCPP HeartBeat Response Not Receive Counts
  88. //============================================
  89. static int HeartBeatWithNOResponse = 0;
  90. //============================================
  91. // OCPP California Pricing Requirements
  92. //============================================
  93. static char dmsVersion[21] = {0};
  94. extern sqlite3 *db;
  95. int TransactionMessageAttemptsGet(void);
  96. int TransactionMessageRetryIntervalGet(void);
  97. int GetOcppConnStatus(void);
  98. void SetOcppConnStatus(uint8_t status);
  99. int setKeyValue(char *key, char *value);
  100. void OCPP_get_TableAuthlocalAllData(void);
  101. void processUnkownKey(void);
  102. struct InterLock
  103. {
  104. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  105. unsigned char isGetDiagnosticGoing:1;
  106. unsigned char isUpdateFirmwareGoing:1;
  107. }interLock;
  108. struct ClientTime
  109. {
  110. struct timespec Heartbeat;
  111. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  112. struct timespec StartTransaction;
  113. struct timespec StopTransaction;
  114. struct timespec MeterValues[CONNECTOR_QUANTITY];
  115. struct timespec RemoteStartWait;
  116. struct timespec TcciQueryDeduct;
  117. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  118. }clientTime;
  119. typedef union
  120. {
  121. //Operations Initiated by Central System
  122. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  123. struct
  124. {
  125. //CsMsgValue[0]
  126. unsigned char StatusNotificationReq:1; //bit 0,
  127. unsigned char StatusNotificationConf:1; //bit 1,
  128. unsigned char TriggerMeterValue:1; //bit 2,
  129. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  130. unsigned char isOnCharging:1; //bit 4.
  131. unsigned char :3; //bit 5~7
  132. }bits[CONNECTOR_QUANTITY];
  133. }CpinitiateMsg;
  134. CpinitiateMsg cpinitateMsg;
  135. //GetConfiguration Array
  136. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  137. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  138. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  139. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  140. static char *ChargePointErrorCodeStr[] = {
  141. MACROSTR(ConnectorLockFailure),
  142. MACROSTR(EVCommunicationError),
  143. MACROSTR(GroundFailure),
  144. MACROSTR(HighTemperature),
  145. MACROSTR(InternalError),
  146. MACROSTR(LocalListConflict),
  147. MACROSTR(NoError),
  148. MACROSTR(OtherError),
  149. MACROSTR(OverCurrentFailure),
  150. MACROSTR(OverVoltage),
  151. MACROSTR(PowerMeterFailure),
  152. MACROSTR(PowerSwitchFailure),
  153. MACROSTR(ReaderFailure),
  154. MACROSTR(ResetFailure),
  155. MACROSTR(UnderVoltage),
  156. MACROSTR(WeakSignal)
  157. };
  158. static char * ChargePointStatusStr[] = {
  159. MACROSTR(Available),
  160. MACROSTR(Preparing),
  161. MACROSTR(Charging),
  162. MACROSTR(SuspendedEVSE),
  163. MACROSTR(SuspendedEV),
  164. MACROSTR(Finishing),
  165. MACROSTR(Reserved),
  166. MACROSTR(Unavailable),
  167. MACROSTR(Faulted)
  168. };
  169. static char *RegistrationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Pending),
  172. MACROSTR(Rejected)
  173. };
  174. static char *AvailabilityTypeStr[] = {
  175. MACROSTR(Inoperative),
  176. MACROSTR(Operative)
  177. };
  178. static char *AvailabilityStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(Scheduled)
  182. };
  183. static char *ConfigurationStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected),
  186. MACROSTR(RebootRequired),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearCacheStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Rejected)
  192. };
  193. static char *ChargingProfilePurposeTypeStr[] = {
  194. MACROSTR(ChargePointMaxProfile),
  195. MACROSTR(TxDefaultProfile),
  196. MACROSTR(TxProfile)
  197. };
  198. static char *ChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Rejected),
  201. MACROSTR(NotSupported)
  202. };
  203. static char *ClearChargingProfileStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Unknown)
  206. };
  207. static char *GetCompositeScheduleStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *UpdateTypeStr[] = {
  212. MACROSTR(Differential),
  213. MACROSTR(Full)
  214. };
  215. static char *UpdateStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Failed),
  218. MACROSTR(NotSupported),
  219. MACROSTR(VersionMismatch)
  220. };
  221. static char *RemoteStartStopStatusStr[] = {
  222. MACROSTR(Accepted),
  223. MACROSTR(Rejected)
  224. };
  225. static char *ReservationStatusStr[] = {
  226. MACROSTR(Accepted),
  227. MACROSTR(Faulted),
  228. MACROSTR(Occupied),
  229. MACROSTR(Rejected),
  230. MACROSTR(Unavailable)
  231. };
  232. static char *ResetTypeStr[] = {
  233. MACROSTR(Hard),
  234. MACROSTR(Soft)
  235. };
  236. static char *ResetStatusStr[] = {
  237. MACROSTR(Accepted),
  238. MACROSTR(Rejected)
  239. };
  240. static char * DiagnosticsStatusStr[] = {
  241. MACROSTR(Idle),
  242. MACROSTR(Uploaded),
  243. MACROSTR(UploadFailed),
  244. MACROSTR(Uploading)
  245. };
  246. static char * FirmwareStatusStr[] = {
  247. MACROSTR(Downloaded),
  248. MACROSTR(DownloadFailed),
  249. MACROSTR(Downloading),
  250. MACROSTR(Idle),
  251. MACROSTR(InstallationFailed),
  252. MACROSTR(Installing),
  253. MACROSTR(Installed)
  254. };
  255. static char * MessageTriggerStr[] = {
  256. MACROSTR(BootNotification),
  257. MACROSTR(DiagnosticsStatusNotification),
  258. MACROSTR(FirmwareStatusNotification),
  259. MACROSTR(Heartbeat),
  260. MACROSTR(MeterValues),
  261. MACROSTR(StatusNotification)
  262. };
  263. static char * TriggerMessageStatusStr[] = {
  264. MACROSTR(Accepted),
  265. MACROSTR(Rejected),
  266. MACROSTR(NotImplemented)
  267. };
  268. static char * UnlockStatusStr[] = {
  269. MACROSTR(Unlocked),
  270. MACROSTR(UnlockFailed),
  271. MACROSTR(NotSupported)
  272. };
  273. #if 0
  274. static char * StopTransactionReasonStr[] = {
  275. MACROSTR(EmergencyStop),
  276. MACROSTR(EVDisconnected),
  277. MACROSTR(HardReset),
  278. MACROSTR(Local),
  279. MACROSTR(Other),
  280. MACROSTR(PowerLoss),
  281. MACROSTR(Reboot),
  282. MACROSTR(Remote),
  283. MACROSTR(SoftReset),
  284. MACROSTR(UnlockCommand),
  285. MACROSTR(DeAuthorized)
  286. };
  287. #endif
  288. static char * CancelReservationStatusStr[] = {
  289. MACROSTR(Accepted),
  290. MACROSTR(Rejected)
  291. };
  292. static char * ReadingContextStr[] = {
  293. MACROSTR(Interruption.Begin),
  294. MACROSTR(Interruption.End),
  295. MACROSTR(Other),
  296. MACROSTR(Sample.Clock),
  297. MACROSTR(Sample.Periodic),
  298. MACROSTR(Transaction.Begin),
  299. MACROSTR(Transaction.End),
  300. MACROSTR(Trigger)
  301. };
  302. static char * ValueFormatStr[] = {
  303. MACROSTR(Raw),
  304. MACROSTR(SignedData)
  305. };
  306. static char * MeasurandStr[] = {
  307. MACROSTR(Current.Export),
  308. MACROSTR(Current.Import),
  309. MACROSTR(Current.Offered),
  310. MACROSTR(Energy.Active.Export.Register),
  311. MACROSTR(Energy.Active.Import.Register),
  312. MACROSTR(Energy.Reactive.Export.Register),
  313. MACROSTR(Energy.Reactive.Import.Register),
  314. MACROSTR(Energy.Active.Export.Interval),
  315. MACROSTR(Energy.Active.Import.Interval),
  316. MACROSTR(Energy.Reactive.Export.Interval),
  317. MACROSTR(Energy.Reactive.Import.Interval),
  318. MACROSTR(Frequency),
  319. MACROSTR(Power.Active.Export),
  320. MACROSTR(Power.Active.Import),
  321. MACROSTR(Power.Factor),
  322. MACROSTR(Power.Offered),
  323. MACROSTR(Power.Reactive.ExportMACROSTR),
  324. MACROSTR(Power.Reactive.Import),
  325. MACROSTR(RPM),
  326. MACROSTR(SoC),
  327. MACROSTR(Temperature),
  328. MACROSTR(Voltage)
  329. };
  330. static char * LocationStr[] = {
  331. MACROSTR(Body),
  332. MACROSTR(Cable),
  333. MACROSTR(EV),
  334. MACROSTR(Inlet),
  335. MACROSTR(Outlet)
  336. };
  337. static char * PhaseStr[] = {
  338. MACROSTR(L1),
  339. MACROSTR(L2),
  340. MACROSTR(L3),
  341. MACROSTR(N),
  342. MACROSTR(L1-N),
  343. MACROSTR(L2-N),
  344. MACROSTR(L3-N),
  345. MACROSTR(L1-L2),
  346. MACROSTR(L2-L3),
  347. MACROSTR(L3-L1)
  348. };
  349. static char * UnitOfMeasureStr[] = {
  350. MACROSTR(Wh),
  351. MACROSTR(kWh),
  352. MACROSTR(varh),
  353. MACROSTR(kvarh),
  354. MACROSTR(W),
  355. MACROSTR(kW),
  356. MACROSTR(VA),
  357. MACROSTR(kVA),
  358. MACROSTR(var),
  359. MACROSTR(kvar),
  360. MACROSTR(A),
  361. MACROSTR(V),
  362. MACROSTR(Celsius),
  363. MACROSTR(Fahrenheit),
  364. MACROSTR(K),
  365. MACROSTR(Percent)
  366. };
  367. //=========================================
  368. // Save configuration
  369. //=========================================
  370. int runShellCmd(const char*cmd)
  371. {
  372. int result = FAIL;
  373. char buf[256];
  374. FILE *fp;
  375. fp = popen(cmd, "r");
  376. if(fp != NULL)
  377. {
  378. while(fgets(buf, sizeof(buf), fp) != NULL)
  379. {
  380. DEBUG_INFO("%s\n", buf);
  381. }
  382. result = PASS;
  383. }
  384. pclose(fp);
  385. return result;
  386. }
  387. int StoreUsrConfigData(struct SysConfigData *UsrData)
  388. {
  389. int result = PASS;
  390. int fd,wrd;
  391. unsigned int i,Chk;
  392. unsigned char *ptr, *BufTmp;
  393. int MtdBlockSize = 0x300000;
  394. Chk=0;
  395. ptr=(unsigned char *)UsrData;
  396. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  397. {
  398. memset(BufTmp,0,MtdBlockSize);
  399. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  400. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  401. Chk+=*(BufTmp+i);
  402. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  403. // Output configuration to file.
  404. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  405. if (fd < 0)
  406. {
  407. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  408. free(BufTmp);
  409. return 0;
  410. }
  411. wrd=write(fd, BufTmp, MtdBlockSize);
  412. close(fd);
  413. if(wrd<MtdBlockSize)
  414. {
  415. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  416. free(BufTmp);
  417. return 0;
  418. }
  419. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  420. DEBUG_INFO("Erase /dev/mtd10.\n");
  421. runShellCmd("flash_erase /dev/mtd10 0 0");
  422. DEBUG_INFO("Write /dev/mtd10.\n");
  423. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  424. DEBUG_INFO("Erase /dev/mtd11.\n");
  425. runShellCmd("flash_erase /dev/mtd11 0 0");
  426. DEBUG_INFO("Write /dev/mtd11.\n");
  427. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  428. system("rm -f /mnt/EvseConfig.bin");
  429. DEBUG_INFO("EvseConfig write to flash OK\n");
  430. }
  431. else
  432. {
  433. DEBUG_ERROR("alloc BlockSize NG\r\n");
  434. result = FAIL;
  435. }
  436. if(BufTmp!=NULL)
  437. free(BufTmp);
  438. return result;
  439. }
  440. //=========================================
  441. // Sqlite3 related function
  442. //=========================================
  443. static int selectSqlCount = 0;
  444. static int callback(void *data, int argc, char **argv, char **azColName){
  445. int i;
  446. //printf("%s: ", (const char*)data);
  447. selectSqlCount = argc;
  448. for(i = 0; i<argc; i++){
  449. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  450. }
  451. //printf("\n");
  452. return 0;
  453. }
  454. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  455. //int i;
  456. //printf("%s:\n", (const char*)data);
  457. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  458. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  459. return 0;
  460. }
  461. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  462. //printf("%s:\n", (const char*)data);
  463. //idTag
  464. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  465. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  466. //parentIdTag
  467. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  468. //expir_date
  469. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  470. //status
  471. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  472. //version
  473. if(columenCount > 5)
  474. idTagQuery.listVersionInt = atoi(columnValue[5]);
  475. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  476. return 0;
  477. }
  478. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  479. {
  480. // localversion = argv[5] ? atoi(argv[5]) : 0;
  481. // printf("localversion=%d\n", localversion);
  482. return 0;
  483. }
  484. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  485. {
  486. for (int i = 0; i < n_columns; i++)
  487. {
  488. DEBUG_INFO("%s\t", col_values[i]);
  489. }
  490. DEBUG_INFO("\n");
  491. return 0;
  492. }
  493. int OCPP_cleanLocalCache()
  494. {
  495. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  496. char *errMsg = 0;
  497. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  498. if (SQLITE_OK != rc)
  499. {
  500. DEBUG_INFO("SQL error: %s\n",errMsg);
  501. return FALSE;
  502. }
  503. return TRUE;
  504. }
  505. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  506. {
  507. int isSuccess = TRUE;
  508. int ret = 0;
  509. //const char* data = "Callback function called";
  510. char sql[300];
  511. char zErrMsg[200];
  512. memset(sql, 0, 300);
  513. memset(zErrMsg, 0, 200);
  514. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  515. //* Execute SQL statement */
  516. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  517. if( ret != SQLITE_OK )
  518. {
  519. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  520. isSuccess = FALSE;
  521. }
  522. return isSuccess;
  523. }
  524. void OCPP_getIdTagFromLocalCache(char idTag[])
  525. {
  526. int rc = 0;
  527. char sql[100];
  528. char zErrMsg[100];
  529. memset(sql, 0, 100);
  530. memset(zErrMsg, 0, 100);
  531. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  532. memset(&idTagQuery, 0, sizeof(idTagQuery));
  533. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  534. /* Execute SQL statement */
  535. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  536. if( rc != SQLITE_OK )
  537. {
  538. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  539. }
  540. }
  541. void OCPP_getListVerion()
  542. {
  543. int rc = 0;
  544. // const char* data = "Callback function called";
  545. char sql[100];
  546. char zErrMsg[100];
  547. memset(sql, 0, 100);
  548. memset(zErrMsg, 0, 100);
  549. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  550. /* Execute SQL statement */
  551. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  552. if( rc != SQLITE_OK )
  553. {
  554. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  555. }
  556. }
  557. void OCPP_get_TableAuthlocalAllData(void)
  558. {
  559. int rc = 0;
  560. char sql[100];
  561. char zErrMsg[100];
  562. memset(sql, 0, 100);
  563. memset(zErrMsg, 0, 100);
  564. sprintf(sql,"select * from ocpp_auth_local ");
  565. /* Execute SQL statement */
  566. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  567. if( rc != SQLITE_OK )
  568. {
  569. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  570. }
  571. //return ver;
  572. }
  573. int OCPP_cleanLocalList()
  574. {
  575. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  576. char *errMsg = 0;
  577. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  578. if (SQLITE_OK != rc)
  579. {
  580. DEBUG_INFO("%s\n",errMsg);
  581. return FALSE;
  582. }
  583. return TRUE;
  584. }
  585. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  586. {
  587. int isSuccess = FALSE;
  588. int ret = 0;
  589. //const char* data = "Callback function called";
  590. char sql[300];
  591. char zErrMsg[200];
  592. memset(sql, 0, 300);
  593. memset(zErrMsg, 0, 200);
  594. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  595. //* Execute SQL statement */
  596. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  597. if( ret != SQLITE_OK )
  598. {
  599. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  600. return isSuccess;
  601. }
  602. memset(sql, 0, 300);
  603. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  604. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  605. if( ret != SQLITE_OK )
  606. {
  607. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  608. return isSuccess;
  609. }
  610. isSuccess = TRUE;
  611. return isSuccess;
  612. }
  613. void OCPP_getIdTagFromLocalList(char idTag[])
  614. {
  615. int rc = 0;
  616. // const char* data = "Callback function called";
  617. char sql[100];
  618. char zErrMsg[100];
  619. memset(sql, 0, 100);
  620. memset(zErrMsg, 0, 100);
  621. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  622. memset(&idTagQuery, 0, sizeof(idTagQuery));
  623. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  624. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  625. /* Execute SQL statement */
  626. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  627. if( rc != SQLITE_OK )
  628. {
  629. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  630. }
  631. //return ver;
  632. }
  633. void OCPP_deleteIdTagFromLocalList(char idTag[])
  634. {
  635. //int ver = 0;
  636. //int isSuccess = FALSE;
  637. int rc = 0;
  638. char sql[100];
  639. char zErrMsg[100];
  640. memset(sql, 0, 100);
  641. memset(zErrMsg, 0, 100);
  642. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  643. //* Execute SQL statement */
  644. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  645. if( rc != SQLITE_OK )
  646. {
  647. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  648. }
  649. }
  650. int getCurrentYear()
  651. {
  652. int result = 0;
  653. time_t CurrentTime;
  654. struct tm *tm;
  655. CurrentTime = time(NULL);
  656. tm=localtime(&CurrentTime);
  657. result = (tm->tm_year + 1900);
  658. return result;
  659. }
  660. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  661. {
  662. int result = PASS;
  663. char* errMsg = NULL;
  664. char sqlStr[8192];
  665. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  666. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  667. {
  668. result = FAIL;
  669. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  670. }
  671. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  672. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  673. {
  674. result = FAIL;
  675. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  676. }
  677. return result;
  678. }
  679. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  680. {
  681. int result = PASS;
  682. char* errMsg = NULL;
  683. char sqlStr[8192];
  684. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  685. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  686. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  687. {
  688. result = FAIL;
  689. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  690. }
  691. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  692. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  693. {
  694. result = FAIL;
  695. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  696. }
  697. return result;
  698. }
  699. int OCPP_update_deduct_info(int txId, char *creditNo)
  700. {
  701. int result = PASS;
  702. char* errMsg = NULL;
  703. char sqlStr[8192];
  704. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  705. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  706. {
  707. result = FAIL;
  708. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  709. }
  710. return result;
  711. }
  712. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  713. {
  714. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  715. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  716. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  717. atoi(columnValue[1]),
  718. columnValue[2],
  719. atoi(columnValue[3])==1?"true":"false",
  720. atoi(columnValue[4])==1?"true":"false",
  721. columnValue[5],
  722. columnValue[9]);
  723. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  724. return 0;
  725. }
  726. void OCPP_query_deduct_info()
  727. {
  728. int rc = 0;
  729. char sql[100];
  730. char zErrMsg[100];
  731. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  732. /* Execute SQL statement */
  733. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  734. if( rc != SQLITE_OK )
  735. {
  736. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  737. }
  738. }
  739. void reportReaderStatus(int gun_index)
  740. {
  741. struct timeval tmnow;
  742. struct tm *tm;
  743. char buf[28];//, usec_buf[6];
  744. gettimeofday(&tmnow, NULL);
  745. time_t t;
  746. t = time(NULL);
  747. /*UTC time and date*/
  748. tm = gmtime(&t);
  749. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  750. #if 0 // remove temporally
  751. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  752. strcat(buf,".");
  753. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  754. strcat(buf,usec_buf);
  755. #endif
  756. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  757. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  758. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  759. (gun_index+1),
  760. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  761. buf,
  762. ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index],
  763. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].creditNo,
  764. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  765. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  766. }
  767. //==========================================
  768. // Check time passed since today
  769. //==========================================
  770. long long DiffTimebWithNow(struct timeb ST)
  771. {
  772. //return milli-second
  773. struct timeb ET;
  774. long long StartTime,StopTime;
  775. ftime(&ET);
  776. StartTime=(long long)ST.time;
  777. StopTime=(long long)ET.time;
  778. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  779. }
  780. int getTimePassSinceToday(uint8_t gun_index)
  781. {
  782. int result = -1;
  783. static time_t lastTime[4];
  784. time_t t;
  785. struct tm *tmStartToday;
  786. struct timeb tbStartToday;
  787. t=time(NULL);
  788. if(difftime(t, lastTime[gun_index])>0)
  789. {
  790. tmStartToday=localtime(&t);
  791. tmStartToday->tm_hour = 0;
  792. tmStartToday->tm_min = 0;
  793. tmStartToday->tm_sec = 0;
  794. tbStartToday.time = mktime(tmStartToday);
  795. tbStartToday.millitm = 0;
  796. result = DiffTimebWithNow(tbStartToday)/1000;
  797. lastTime[gun_index] = t;
  798. }
  799. return result;
  800. }
  801. void getNowDatetime(uint8_t *data)
  802. {
  803. time_t t = time(NULL);
  804. struct tm tm = *localtime(&t);
  805. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  806. }
  807. int syncDateTimeRTC(uint8_t *data)
  808. {
  809. struct ParsingResult
  810. {
  811. int result;
  812. int scanedElement;
  813. int year;
  814. int month;
  815. int mday;
  816. int hour;
  817. int min;
  818. int sec;
  819. int tz_hour;
  820. int tz_min;
  821. float minSec;
  822. }result;
  823. struct tm tmOrg;
  824. struct tm *tmTarget;
  825. struct timeb tbTarget;
  826. char buf[128];
  827. memset(&result, 0x00, sizeof(struct ParsingResult));
  828. result.result = PASS;
  829. if(strstr((char*)data, ".") != NULL)
  830. {
  831. // Original data with mini second
  832. if(strstr((char*)data, "Z") != NULL)
  833. {
  834. // Original data with Z
  835. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  836. &result.year,
  837. &result.month,
  838. &result.mday,
  839. &result.hour,
  840. &result.min,
  841. &result.sec,
  842. &result.minSec);
  843. }
  844. else
  845. {
  846. // Original data without Z
  847. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  848. &result.year,
  849. &result.month,
  850. &result.mday,
  851. &result.hour,
  852. &result.min,
  853. &result.sec,
  854. &result.minSec,
  855. &result.tz_hour,
  856. &result.tz_min);
  857. }
  858. }
  859. else
  860. {
  861. // Original data without mini second
  862. if(strstr((char*)data, "Z") != NULL)
  863. {
  864. // Original data with Z
  865. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  866. &result.year,
  867. &result.month,
  868. &result.mday,
  869. &result.hour,
  870. &result.min,
  871. &result.sec);
  872. }
  873. else
  874. {
  875. // Original data without Z
  876. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  877. &result.year,
  878. &result.month,
  879. &result.mday,
  880. &result.hour,
  881. &result.min,
  882. &result.sec,
  883. &result.tz_hour,
  884. &result.tz_min);
  885. }
  886. }
  887. tmOrg.tm_year = result.year - 1900;
  888. tmOrg.tm_mon = result.month - 1;
  889. tmOrg.tm_mday = result.mday;
  890. tmOrg.tm_hour = result.hour;
  891. tmOrg.tm_min = result.min;
  892. tmOrg.tm_sec = result.sec;
  893. tmOrg.tm_gmtoff = 0;
  894. tbTarget.time = mktime(&tmOrg);
  895. tbTarget.timezone = 0;
  896. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  897. tmTarget = gmtime(&tbTarget.time);
  898. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  899. //DEBUG_INFO(" org date time: %s\n", data);
  900. //DEBUG_INFO("parse date time: %s\n", buf);
  901. system(buf);
  902. system("/sbin/hwclock -w --systohc");
  903. if(result.scanedElement < 6)
  904. result.result = FAIL;
  905. return result.result;
  906. }
  907. //==========================================
  908. // GetCompositeSchedule logic related function
  909. //==========================================
  910. int DiffTimebSec(struct timeb ST, struct timeb ET)
  911. {
  912. //return milli-second
  913. unsigned int StartTime,StopTime;
  914. StartTime=(unsigned int)ST.time;
  915. StopTime=(unsigned int)ET.time;
  916. return (StopTime-StartTime);
  917. }
  918. int DiffTimebWithNowSec(struct timeb ST)
  919. {
  920. //return milli-second
  921. struct timeb ET;
  922. unsigned int StartTime,StopTime;
  923. ftime(&ET);
  924. StartTime=(unsigned int)ST.time;
  925. StopTime=(unsigned int)ET.time;
  926. return (StopTime-StartTime);
  927. }
  928. int getStartStop(uint8_t *start, uint8_t *stop)
  929. {
  930. struct ParsingResult
  931. {
  932. int result;
  933. int scanedElement;
  934. int year;
  935. int month;
  936. int mday;
  937. int hour;
  938. int min;
  939. int sec;
  940. int tz_hour;
  941. int tz_min;
  942. float minSec;
  943. };
  944. struct ParsingResult parseStart;
  945. struct ParsingResult parseStop;
  946. int result = -1;
  947. struct tm tmStart;
  948. struct timeb tbStart;
  949. struct tm tmStop;
  950. struct timeb tbStop;
  951. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  952. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  953. // Scan start & stop date time
  954. if(strstr((char*)start, ".") != NULL)
  955. {
  956. // Original data with mini second
  957. if(strstr((char*)start, "Z") != NULL)
  958. {
  959. // Original data with Z
  960. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  961. &parseStart.year,
  962. &parseStart.month,
  963. &parseStart.mday,
  964. &parseStart.hour,
  965. &parseStart.min,
  966. &parseStart.sec,
  967. &parseStart.minSec);
  968. }
  969. else
  970. {
  971. // Original data without Z
  972. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  973. &parseStart.year,
  974. &parseStart.month,
  975. &parseStart.mday,
  976. &parseStart.hour,
  977. &parseStart.min,
  978. &parseStart.sec,
  979. &parseStart.minSec,
  980. &parseStart.tz_hour,
  981. &parseStart.tz_min);
  982. }
  983. }
  984. else
  985. {
  986. // Original data without mini second
  987. if(strstr((char*)start, "Z") != NULL)
  988. {
  989. // Original data with Z
  990. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  991. &parseStart.year,
  992. &parseStart.month,
  993. &parseStart.mday,
  994. &parseStart.hour,
  995. &parseStart.min,
  996. &parseStart.sec);
  997. }
  998. else
  999. {
  1000. // Original data without Z
  1001. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1002. &parseStart.year,
  1003. &parseStart.month,
  1004. &parseStart.mday,
  1005. &parseStart.hour,
  1006. &parseStart.min,
  1007. &parseStart.sec,
  1008. &parseStart.tz_hour,
  1009. &parseStart.tz_min);
  1010. }
  1011. }
  1012. if(strstr((char*)stop, ".") != NULL)
  1013. {
  1014. // Original data with mini second
  1015. if(strstr((char*)stop, "Z") != NULL)
  1016. {
  1017. // Original data with Z
  1018. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1019. &parseStop.year,
  1020. &parseStop.month,
  1021. &parseStop.mday,
  1022. &parseStop.hour,
  1023. &parseStop.min,
  1024. &parseStop.sec,
  1025. &parseStop.minSec);
  1026. }
  1027. else
  1028. {
  1029. // Original data without Z
  1030. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1031. &parseStop.year,
  1032. &parseStop.month,
  1033. &parseStop.mday,
  1034. &parseStop.hour,
  1035. &parseStop.min,
  1036. &parseStop.sec,
  1037. &parseStop.minSec,
  1038. &parseStop.tz_hour,
  1039. &parseStop.tz_min);
  1040. }
  1041. }
  1042. else
  1043. {
  1044. // Original data without mini second
  1045. if(strstr((char*)stop, "Z") != NULL)
  1046. {
  1047. // Original data with Z
  1048. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1049. &parseStop.year,
  1050. &parseStop.month,
  1051. &parseStop.mday,
  1052. &parseStop.hour,
  1053. &parseStop.min,
  1054. &parseStop.sec);
  1055. }
  1056. else
  1057. {
  1058. // Original data without Z
  1059. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1060. &parseStop.year,
  1061. &parseStop.month,
  1062. &parseStop.mday,
  1063. &parseStop.hour,
  1064. &parseStop.min,
  1065. &parseStop.sec,
  1066. &parseStop.tz_hour,
  1067. &parseStop.tz_min);
  1068. }
  1069. }
  1070. // Calculate date time difference
  1071. if((parseStart.scanedElement >=6) &&
  1072. (parseStop.scanedElement >=6))
  1073. {
  1074. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1075. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1076. tmStart.tm_year = parseStart.year - 1900;
  1077. tmStart.tm_mon = parseStart.month - 1;
  1078. tmStart.tm_mday = parseStart.mday;
  1079. tmStart.tm_hour = parseStart.hour;
  1080. tmStart.tm_min = parseStart.min;
  1081. tmStart.tm_sec = parseStart.sec;
  1082. tmStart.tm_gmtoff = 0;
  1083. tbStart.time = mktime(&tmStart);
  1084. tbStart.timezone = 0;
  1085. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1086. tmStop.tm_year = parseStop.year - 1900;
  1087. tmStop.tm_mon = parseStop.month - 1;
  1088. tmStop.tm_mday = parseStop.mday;
  1089. tmStop.tm_hour = parseStop.hour;
  1090. tmStop.tm_min = parseStop.min;
  1091. tmStop.tm_sec = parseStop.sec;
  1092. tmStop.tm_gmtoff = 0;
  1093. tbStop.time = mktime(&tmStop);
  1094. tbStop.timezone = 0;
  1095. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1096. result = DiffTimebSec(tbStart, tbStop);
  1097. //DEBUG_INFO("getStartStop(): %d\n", result);
  1098. }
  1099. else
  1100. {
  1101. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1102. }
  1103. return result;
  1104. }
  1105. int isOvertNow(uint8_t *start)
  1106. {
  1107. int result = NO;
  1108. struct ParsingResult
  1109. {
  1110. int result;
  1111. int scanedElement;
  1112. int year;
  1113. int month;
  1114. int mday;
  1115. int hour;
  1116. int min;
  1117. int sec;
  1118. int tz_hour;
  1119. int tz_min;
  1120. float minSec;
  1121. }parsingResult;
  1122. struct tm tmStart;
  1123. struct timeb tbStart;
  1124. if(strstr((char*)start, ".") != NULL)
  1125. {
  1126. // Original data with mini second
  1127. if(strstr((char*)start, "Z") != NULL)
  1128. {
  1129. // Original data with Z
  1130. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1131. &parsingResult.year,
  1132. &parsingResult.month,
  1133. &parsingResult.mday,
  1134. &parsingResult.hour,
  1135. &parsingResult.min,
  1136. &parsingResult.sec,
  1137. &parsingResult.minSec);
  1138. }
  1139. else
  1140. {
  1141. // Original data without Z
  1142. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1143. &parsingResult.year,
  1144. &parsingResult.month,
  1145. &parsingResult.mday,
  1146. &parsingResult.hour,
  1147. &parsingResult.min,
  1148. &parsingResult.sec,
  1149. &parsingResult.minSec,
  1150. &parsingResult.tz_hour,
  1151. &parsingResult.tz_min);
  1152. }
  1153. }
  1154. else
  1155. {
  1156. // Original data without mini second
  1157. if(strstr((char*)start, "Z") != NULL)
  1158. {
  1159. // Original data with Z
  1160. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1161. &parsingResult.year,
  1162. &parsingResult.month,
  1163. &parsingResult.mday,
  1164. &parsingResult.hour,
  1165. &parsingResult.min,
  1166. &parsingResult.sec);
  1167. }
  1168. else
  1169. {
  1170. // Original data without Z
  1171. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1172. &parsingResult.year,
  1173. &parsingResult.month,
  1174. &parsingResult.mday,
  1175. &parsingResult.hour,
  1176. &parsingResult.min,
  1177. &parsingResult.sec,
  1178. &parsingResult.tz_hour,
  1179. &parsingResult.tz_min);
  1180. }
  1181. }
  1182. if(parsingResult.scanedElement >= 6)
  1183. {
  1184. tmStart.tm_year = parsingResult.year - 1900;
  1185. tmStart.tm_mon = parsingResult.month - 1;
  1186. tmStart.tm_mday = parsingResult.mday;
  1187. tmStart.tm_hour = parsingResult.hour;
  1188. tmStart.tm_min = parsingResult.min;
  1189. tmStart.tm_sec = parsingResult.sec;
  1190. tmStart.tm_gmtoff = 0;
  1191. tbStart.time = mktime(&tmStart);
  1192. tbStart.timezone = 0;
  1193. tbStart.millitm = 0;
  1194. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1195. if(DiffTimebWithNowSec(tbStart) <= 0)
  1196. result = NO;
  1197. else
  1198. result = YES;
  1199. }
  1200. else
  1201. {
  1202. DEBUG_WARN("Start date parsing error.\n");
  1203. }
  1204. return result;
  1205. }
  1206. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1207. {
  1208. struct ParsingResult
  1209. {
  1210. int result;
  1211. int scanedElement;
  1212. int year;
  1213. int month;
  1214. int mday;
  1215. int hour;
  1216. int min;
  1217. int sec;
  1218. int tz_hour;
  1219. int tz_min;
  1220. float minSec;
  1221. };
  1222. struct ParsingResult parseStart;
  1223. struct ParsingResult parseStop;
  1224. int result = -1;
  1225. struct tm tmStart;
  1226. struct timeb tbStart;
  1227. struct tm tmStop;
  1228. struct timeb tbStop;
  1229. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1230. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1231. // Scan start & stop date time
  1232. if(strstr((char*)start, ".") != NULL)
  1233. {
  1234. // Original data with mini second
  1235. if(strstr((char*)start, "Z") != NULL)
  1236. {
  1237. // Original data with Z
  1238. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1239. &parseStart.year,
  1240. &parseStart.month,
  1241. &parseStart.mday,
  1242. &parseStart.hour,
  1243. &parseStart.min,
  1244. &parseStart.sec,
  1245. &parseStart.minSec);
  1246. }
  1247. else
  1248. {
  1249. // Original data without Z
  1250. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1251. &parseStart.year,
  1252. &parseStart.month,
  1253. &parseStart.mday,
  1254. &parseStart.hour,
  1255. &parseStart.min,
  1256. &parseStart.sec,
  1257. &parseStart.minSec,
  1258. &parseStart.tz_hour,
  1259. &parseStart.tz_min);
  1260. }
  1261. }
  1262. else
  1263. {
  1264. // Original data without mini second
  1265. if(strstr((char*)start, "Z") != NULL)
  1266. {
  1267. // Original data with Z
  1268. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1269. &parseStart.year,
  1270. &parseStart.month,
  1271. &parseStart.mday,
  1272. &parseStart.hour,
  1273. &parseStart.min,
  1274. &parseStart.sec);
  1275. }
  1276. else
  1277. {
  1278. // Original data without Z
  1279. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1280. &parseStart.year,
  1281. &parseStart.month,
  1282. &parseStart.mday,
  1283. &parseStart.hour,
  1284. &parseStart.min,
  1285. &parseStart.sec,
  1286. &parseStart.tz_hour,
  1287. &parseStart.tz_min);
  1288. }
  1289. }
  1290. if(strstr((char*)stop, ".") != NULL)
  1291. {
  1292. // Original data with mini second
  1293. if(strstr((char*)stop, "Z") != NULL)
  1294. {
  1295. // Original data with Z
  1296. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1297. &parseStop.year,
  1298. &parseStop.month,
  1299. &parseStop.mday,
  1300. &parseStop.hour,
  1301. &parseStop.min,
  1302. &parseStop.sec,
  1303. &parseStop.minSec);
  1304. }
  1305. else
  1306. {
  1307. // Original data without Z
  1308. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1309. &parseStop.year,
  1310. &parseStop.month,
  1311. &parseStop.mday,
  1312. &parseStop.hour,
  1313. &parseStop.min,
  1314. &parseStop.sec,
  1315. &parseStop.minSec,
  1316. &parseStop.tz_hour,
  1317. &parseStop.tz_min);
  1318. }
  1319. }
  1320. else
  1321. {
  1322. // Original data without mini second
  1323. if(strstr((char*)stop, "Z") != NULL)
  1324. {
  1325. // Original data with Z
  1326. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1327. &parseStop.year,
  1328. &parseStop.month,
  1329. &parseStop.mday,
  1330. &parseStop.hour,
  1331. &parseStop.min,
  1332. &parseStop.sec);
  1333. }
  1334. else
  1335. {
  1336. // Original data without Z
  1337. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1338. &parseStop.year,
  1339. &parseStop.month,
  1340. &parseStop.mday,
  1341. &parseStop.hour,
  1342. &parseStop.min,
  1343. &parseStop.sec,
  1344. &parseStop.tz_hour,
  1345. &parseStop.tz_min);
  1346. }
  1347. }
  1348. // Calculate date time difference
  1349. if((parseStart.scanedElement >=6) &&
  1350. (parseStop.scanedElement >=6))
  1351. {
  1352. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1353. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1354. tmStart.tm_year = parseStart.year - 1900;
  1355. tmStart.tm_mon = parseStart.month - 1;
  1356. tmStart.tm_mday = parseStart.mday;
  1357. tmStart.tm_hour = parseStart.hour;
  1358. tmStart.tm_min = parseStart.min;
  1359. tmStart.tm_sec = parseStart.sec;
  1360. tmStart.tm_gmtoff = 0;
  1361. tbStart.time = mktime(&tmStart);
  1362. tbStart.timezone = 0;
  1363. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1364. tmStop.tm_year = parseStop.year - 1900;
  1365. tmStop.tm_mon = parseStop.month - 1;
  1366. tmStop.tm_mday = parseStop.mday;
  1367. tmStop.tm_hour = parseStop.hour;
  1368. tmStop.tm_min = parseStop.min;
  1369. tmStop.tm_sec = parseStop.sec;
  1370. tmStop.tm_gmtoff = 0;
  1371. tbStop.time = mktime(&tmStop);
  1372. tbStop.timezone = 0;
  1373. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1374. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1375. //DEBUG_INFO("getStartStop(): %d\n", result);
  1376. }
  1377. else
  1378. {
  1379. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1380. }
  1381. return result;
  1382. }
  1383. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1384. {
  1385. FILE *fp;
  1386. char profileFileName[128];
  1387. char *line = NULL;
  1388. size_t len = 0;
  1389. time_t CurrentTime;
  1390. struct tm *tmComposite;
  1391. struct StructChargingProfile maxProfile;
  1392. struct StructChargingProfile compositeProfile;
  1393. uint8_t limitMax=0;
  1394. int compositePeriodIdx = 0;
  1395. //uint8_t isDurationNull = FALSE;
  1396. CurrentTime = time(NULL);
  1397. tmComposite=localtime(&CurrentTime);
  1398. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1399. if(isUnitA)
  1400. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1401. else
  1402. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1403. compositeProfile.ChargingSchedule.Duration = durationReq;
  1404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1405. {
  1406. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1407. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1408. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1409. }
  1410. compositeProfile.ChargingProfileId = 0;
  1411. compositeProfile.StackLevel = 99 ;
  1412. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1413. maxProfile.ChargingProfileId = -1;
  1414. maxProfile.ChargingSchedule.Duration = -1;
  1415. system("rm -f /tmp/*.json");
  1416. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1417. // Search max profile
  1418. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1419. if((access(profileFileName, F_OK))!=-1)
  1420. {
  1421. fp = fopen(profileFileName, "r");
  1422. while(getline(&line, &len, fp) != -1)
  1423. {
  1424. json_object *obj = NULL;
  1425. obj = json_tokener_parse(line);
  1426. if(is_error(obj))
  1427. {
  1428. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1429. }
  1430. else
  1431. {
  1432. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1433. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1434. )
  1435. {
  1436. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1437. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1438. )
  1439. {
  1440. struct tm tmFrom, tmTo;
  1441. struct timeb tbFrom, tbTo;
  1442. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1443. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1444. {
  1445. tmFrom.tm_year -= 1900;
  1446. tmFrom.tm_mon -= 1;
  1447. tbFrom.time = mktime(&tmFrom);
  1448. tmTo.tm_year -= 1900;
  1449. tmTo.tm_mon -= 1;
  1450. tbTo.time = mktime(&tmTo);
  1451. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1452. {
  1453. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1454. {
  1455. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1456. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1457. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1458. }
  1459. if(maxProfile.ChargingProfileId == -1)
  1460. DEBUG_INFO("MaxProfile found.\n");
  1461. else
  1462. DEBUG_INFO("MaxProfile updated.\n");
  1463. // Required item
  1464. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1465. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1466. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1467. if(isUnitA)
  1468. {
  1469. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1470. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1471. {
  1472. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1473. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1474. 3:
  1475. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1476. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1477. }
  1478. }
  1479. else
  1480. {
  1481. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1482. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1483. {
  1484. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1485. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1486. 3:
  1487. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1488. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1489. }
  1490. }
  1491. // Optional item
  1492. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1493. {
  1494. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1495. }
  1496. else
  1497. {
  1498. sprintf((char*)maxProfile.ValidFrom, " ");
  1499. }
  1500. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1501. {
  1502. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1503. }
  1504. else
  1505. {
  1506. sprintf((char*)maxProfile.ValidTo, " ");
  1507. }
  1508. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1509. {
  1510. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1511. }
  1512. else
  1513. {
  1514. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1515. }
  1516. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1517. {
  1518. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1519. }
  1520. else
  1521. {
  1522. maxProfile.TransactionId = -1;
  1523. }
  1524. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1525. {
  1526. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1527. }
  1528. else
  1529. {
  1530. maxProfile.ChargingSchedule.Duration = 86400;
  1531. //isDurationNull = TRUE;
  1532. }
  1533. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1534. {
  1535. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1536. }
  1537. else
  1538. {
  1539. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1540. }
  1541. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1542. {
  1543. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1544. }
  1545. else
  1546. {
  1547. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1548. }
  1549. }
  1550. }
  1551. }
  1552. else
  1553. {
  1554. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1555. {
  1556. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1557. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1558. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1559. }
  1560. if(maxProfile.ChargingProfileId == -1)
  1561. DEBUG_INFO("MaxProfile found.\n");
  1562. else
  1563. DEBUG_INFO("MaxProfile updated.\n");
  1564. // Required item
  1565. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1566. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1567. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1568. if(isUnitA)
  1569. {
  1570. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1571. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1572. {
  1573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1575. 3:
  1576. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1577. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1578. }
  1579. }
  1580. else
  1581. {
  1582. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1583. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1584. {
  1585. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1586. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1587. 3:
  1588. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1589. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1590. }
  1591. }
  1592. // Optional item
  1593. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1594. {
  1595. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1596. }
  1597. else
  1598. {
  1599. sprintf((char*)maxProfile.ValidFrom, " ");
  1600. }
  1601. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1602. {
  1603. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1604. }
  1605. else
  1606. {
  1607. sprintf((char*)maxProfile.ValidTo, " ");
  1608. }
  1609. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1610. {
  1611. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1612. }
  1613. else
  1614. {
  1615. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1616. }
  1617. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1618. {
  1619. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1620. }
  1621. else
  1622. {
  1623. maxProfile.TransactionId = -1;
  1624. }
  1625. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1626. {
  1627. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1628. }
  1629. else
  1630. {
  1631. maxProfile.ChargingSchedule.Duration = 86400;
  1632. //isDurationNull = TRUE;
  1633. }
  1634. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1635. {
  1636. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1637. }
  1638. else
  1639. {
  1640. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1641. }
  1642. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1643. {
  1644. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1645. }
  1646. else
  1647. {
  1648. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1649. }
  1650. }
  1651. }
  1652. }
  1653. json_object_put(obj);
  1654. }
  1655. fclose(fp);
  1656. /*
  1657. if(maxProfile.ChargingProfileId !=-1)
  1658. {
  1659. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1660. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1661. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1662. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1663. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1664. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1665. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1666. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1667. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1668. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1669. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1670. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1671. {
  1672. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1673. {
  1674. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1675. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1676. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1677. }
  1678. }
  1679. }
  1680. else
  1681. DEBUG_INFO("MaxProfile not found.\n");
  1682. DEBUG_INFO("------------------------------------\n");*/
  1683. }
  1684. if(maxProfile.ChargingProfileId != -1)
  1685. {
  1686. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1687. {
  1688. if(maxProfile.ChargingSchedule.Duration != -1)
  1689. {
  1690. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1691. 0:
  1692. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1693. }
  1694. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1695. {
  1696. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1697. {
  1698. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1699. 0:
  1700. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1701. if(idxPeriod > 0)
  1702. {
  1703. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1704. {
  1705. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1706. }
  1707. }
  1708. }
  1709. }
  1710. }
  1711. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1712. {
  1713. if(maxProfile.ChargingSchedule.Duration != -1)
  1714. {
  1715. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1716. }
  1717. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1718. {
  1719. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1720. {
  1721. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1722. if(idxPeriod > 0)
  1723. {
  1724. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1725. {
  1726. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1727. }
  1728. }
  1729. }
  1730. }
  1731. }
  1732. else
  1733. {
  1734. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1735. {
  1736. if(maxProfile.ChargingSchedule.Duration != -1)
  1737. {
  1738. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1739. 0:
  1740. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1741. }
  1742. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1743. {
  1744. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1745. {
  1746. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1747. 0:
  1748. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1749. if(idxPeriod > 0)
  1750. {
  1751. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1752. {
  1753. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1754. }
  1755. }
  1756. }
  1757. }
  1758. }
  1759. else
  1760. {
  1761. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  1762. {
  1763. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1764. 0:
  1765. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1766. }
  1767. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1768. {
  1769. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1770. {
  1771. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1772. 0:
  1773. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1774. if(idxPeriod > 0)
  1775. {
  1776. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1777. {
  1778. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1779. }
  1780. }
  1781. }
  1782. }
  1783. }
  1784. }
  1785. /*
  1786. DEBUG_INFO("MaxProfile after align.\n");
  1787. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1788. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1789. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1790. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1791. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1792. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1793. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1794. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1795. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1796. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1797. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1798. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1799. {
  1800. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1801. {
  1802. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1803. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1804. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1805. }
  1806. }
  1807. DEBUG_INFO("------------------------------------\n");*/
  1808. }
  1809. // Find each profile period quantity
  1810. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1811. {
  1812. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1813. limitMax = idx+1;
  1814. }
  1815. if(maxProfile.ChargingProfileId != -1)
  1816. {
  1817. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1818. {
  1819. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1820. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1821. (maxProfile.ChargingSchedule.Duration > 0))
  1822. {
  1823. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1824. {
  1825. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1826. compositePeriodIdx++;
  1827. }
  1828. else
  1829. {
  1830. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1831. }
  1832. }
  1833. }
  1834. }
  1835. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1836. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1837. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1838. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1839. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1840. {
  1841. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1842. {
  1843. compositeProfile.ChargingProfileId = 1;
  1844. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1845. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1846. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1847. }
  1848. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1849. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1850. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1851. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1852. }
  1853. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1854. if(line)
  1855. free(line);
  1856. }
  1857. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1858. {
  1859. FILE *fp;
  1860. char profileFileName[128];
  1861. char *line = NULL;
  1862. size_t len = 0;
  1863. time_t CurrentTime;
  1864. struct tm *tmComposite;
  1865. struct StructChargingProfile maxProfile;
  1866. struct StructChargingProfile defaultTxProfile;
  1867. struct StructChargingProfile txProfile;
  1868. struct StructChargingProfile compositeProfile;
  1869. struct StructChargingSchedulePeriod tmpPeriod;
  1870. uint8_t limitMax=0;
  1871. uint8_t limitDef=0;
  1872. uint8_t limitTx=0;
  1873. int compositePeriodIdx = 0;
  1874. CurrentTime = time(NULL);
  1875. tmComposite=localtime(&CurrentTime);
  1876. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1877. if(isUnitA)
  1878. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1879. else
  1880. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1881. compositeProfile.ChargingSchedule.Duration = durationReq;
  1882. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1883. {
  1884. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1885. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1886. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1887. }
  1888. compositeProfile.ChargingProfileId = 0;
  1889. compositeProfile.StackLevel = 99 ;
  1890. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1891. maxProfile.ChargingProfileId = -1;
  1892. defaultTxProfile.ChargingProfileId = -1;
  1893. txProfile.ChargingProfileId = -1;
  1894. maxProfile.ChargingSchedule.Duration = -1;
  1895. defaultTxProfile.ChargingSchedule.Duration = -1;
  1896. txProfile.ChargingSchedule.Duration = -1;
  1897. system("rm -f /tmp/*.json");
  1898. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1899. /*
  1900. * Search valid charging profile
  1901. */
  1902. //DEBUG_INFO("====================================\n");
  1903. // Search tx profile
  1904. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1905. if((access(profileFileName, F_OK))!=-1)
  1906. {
  1907. fp = fopen(profileFileName, "r");
  1908. while(getline(&line, &len, fp) != -1)
  1909. {
  1910. json_object *obj = NULL;
  1911. obj = json_tokener_parse(line);
  1912. if(is_error(obj))
  1913. {
  1914. DEBUG_ERROR("Parse txProfile from file error.\n");
  1915. }
  1916. else
  1917. {
  1918. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1919. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1920. )
  1921. {
  1922. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1923. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1924. )
  1925. {
  1926. struct tm tmFrom, tmTo;
  1927. struct timeb tbFrom, tbTo;
  1928. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1929. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1930. {
  1931. tmFrom.tm_year -= 1900;
  1932. tmFrom.tm_mon -= 1;
  1933. tbFrom.time = mktime(&tmFrom);
  1934. tmTo.tm_year -= 1900;
  1935. tmTo.tm_mon -= 1;
  1936. tbTo.time = mktime(&tmTo);
  1937. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1938. {
  1939. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1940. {
  1941. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1942. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1943. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1944. }
  1945. if(txProfile.ChargingProfileId == -1)
  1946. DEBUG_INFO("TxProfile found.\n");
  1947. else
  1948. DEBUG_INFO("TxProfile updated.\n");
  1949. // Required item
  1950. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1951. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1952. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1953. if(isUnitA)
  1954. {
  1955. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1956. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1957. {
  1958. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1959. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1960. 3:
  1961. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1962. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1963. }
  1964. }
  1965. else
  1966. {
  1967. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1968. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1969. {
  1970. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1971. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1972. 3:
  1973. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1974. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1975. }
  1976. }
  1977. // Optional item
  1978. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1979. {
  1980. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1981. }
  1982. else
  1983. {
  1984. sprintf((char*)txProfile.ValidFrom, " ");
  1985. }
  1986. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1987. {
  1988. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1989. }
  1990. else
  1991. {
  1992. sprintf((char*)txProfile.ValidTo, " ");
  1993. }
  1994. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1995. {
  1996. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1997. }
  1998. else
  1999. {
  2000. sprintf((char*)txProfile.RecurrencyKind, " ");
  2001. }
  2002. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2003. {
  2004. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2005. }
  2006. else
  2007. {
  2008. txProfile.TransactionId = -1;
  2009. }
  2010. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2011. {
  2012. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2013. }
  2014. else
  2015. {
  2016. txProfile.ChargingSchedule.Duration = 86400;
  2017. }
  2018. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2019. {
  2020. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2021. }
  2022. else
  2023. {
  2024. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2025. }
  2026. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2027. {
  2028. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2029. }
  2030. else
  2031. {
  2032. txProfile.ChargingSchedule.MinChargingRate = -1;
  2033. }
  2034. }
  2035. }
  2036. }
  2037. else
  2038. {
  2039. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2040. {
  2041. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2042. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2043. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2044. }
  2045. if(txProfile.ChargingProfileId == -1)
  2046. DEBUG_INFO("TxProfile found.\n");
  2047. else
  2048. DEBUG_INFO("TxProfile updated.\n");
  2049. // Required item
  2050. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2051. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2052. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2053. if(isUnitA)
  2054. {
  2055. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2056. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2057. {
  2058. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2059. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2060. 3:
  2061. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2062. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2063. }
  2064. }
  2065. else
  2066. {
  2067. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2068. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2069. {
  2070. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2071. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2072. 3:
  2073. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2074. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2075. }
  2076. }
  2077. // Optional item
  2078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2079. {
  2080. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2081. }
  2082. else
  2083. {
  2084. sprintf((char*)txProfile.ValidFrom, " ");
  2085. }
  2086. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2087. {
  2088. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2089. }
  2090. else
  2091. {
  2092. sprintf((char*)txProfile.ValidTo, " ");
  2093. }
  2094. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2095. {
  2096. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2097. }
  2098. else
  2099. {
  2100. sprintf((char*)txProfile.RecurrencyKind, " ");
  2101. }
  2102. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2103. {
  2104. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2105. }
  2106. else
  2107. {
  2108. txProfile.TransactionId = -1;
  2109. }
  2110. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2111. {
  2112. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2113. }
  2114. else
  2115. {
  2116. txProfile.ChargingSchedule.Duration = 86400;
  2117. }
  2118. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2119. {
  2120. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2121. }
  2122. else
  2123. {
  2124. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2125. }
  2126. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2127. {
  2128. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2129. }
  2130. else
  2131. {
  2132. txProfile.ChargingSchedule.MinChargingRate = -1;
  2133. }
  2134. }
  2135. }
  2136. }
  2137. json_object_put(obj);
  2138. }
  2139. fclose(fp);
  2140. /*
  2141. if(txProfile.ChargingProfileId != -1)
  2142. {
  2143. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2144. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2145. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2146. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2147. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2148. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2149. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2150. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2151. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2152. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2153. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2154. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2155. {
  2156. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2157. {
  2158. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2159. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2160. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2161. }
  2162. }
  2163. }
  2164. else
  2165. DEBUG_INFO("TxProfile not found.\n");*/
  2166. }
  2167. // Search default tx profile
  2168. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2169. if((access(profileFileName, F_OK))==-1)
  2170. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2171. if((access(profileFileName, F_OK))!=-1)
  2172. {
  2173. fp = fopen(profileFileName, "r");
  2174. while(getline(&line, &len, fp) != -1)
  2175. {
  2176. json_object *obj = NULL;
  2177. obj = json_tokener_parse(line);
  2178. if(is_error(obj))
  2179. {
  2180. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2181. }
  2182. else
  2183. {
  2184. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2185. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2186. )
  2187. {
  2188. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2189. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2190. )
  2191. {
  2192. struct tm tmFrom, tmTo;
  2193. struct timeb tbFrom, tbTo;
  2194. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2195. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2196. {
  2197. tmFrom.tm_year -= 1900;
  2198. tmFrom.tm_mon -= 1;
  2199. tbFrom.time = mktime(&tmFrom);
  2200. tmTo.tm_year -= 1900;
  2201. tmTo.tm_mon -= 1;
  2202. tbTo.time = mktime(&tmTo);
  2203. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2204. {
  2205. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2206. {
  2207. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2208. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2209. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2210. }
  2211. if(defaultTxProfile.ChargingProfileId == -1)
  2212. DEBUG_INFO("TxDefaultProfile found.\n");
  2213. else
  2214. DEBUG_INFO("TxDefaultProfile updated.\n");
  2215. // Required item
  2216. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2217. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2218. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2219. if(isUnitA)
  2220. {
  2221. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2222. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2223. {
  2224. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2225. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2226. 3:
  2227. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2228. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2229. }
  2230. }
  2231. else
  2232. {
  2233. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2234. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2235. {
  2236. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2237. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2238. 3:
  2239. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2240. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2241. }
  2242. }
  2243. // Optional item
  2244. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2245. {
  2246. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2247. }
  2248. else
  2249. {
  2250. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2251. }
  2252. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2253. {
  2254. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2255. }
  2256. else
  2257. {
  2258. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2259. }
  2260. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2261. {
  2262. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2263. }
  2264. else
  2265. {
  2266. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2267. }
  2268. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2269. {
  2270. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2271. }
  2272. else
  2273. {
  2274. defaultTxProfile.TransactionId = -1;
  2275. }
  2276. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2277. {
  2278. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2279. }
  2280. else
  2281. {
  2282. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2283. }
  2284. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2285. {
  2286. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2287. }
  2288. else
  2289. {
  2290. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2291. }
  2292. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2293. {
  2294. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2295. }
  2296. else
  2297. {
  2298. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2299. }
  2300. }
  2301. }
  2302. }
  2303. else
  2304. {
  2305. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2306. {
  2307. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2308. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2309. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2310. }
  2311. if(defaultTxProfile.ChargingProfileId == -1)
  2312. DEBUG_INFO("TxDefaultProfile found.\n");
  2313. else
  2314. DEBUG_INFO("TxDefaultProfile updated.\n");
  2315. // Required item
  2316. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2317. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2318. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2319. if(isUnitA)
  2320. {
  2321. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2322. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2323. {
  2324. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2325. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2326. 3:
  2327. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2328. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2329. }
  2330. }
  2331. else
  2332. {
  2333. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2334. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2335. {
  2336. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2337. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2338. 3:
  2339. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2340. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2341. }
  2342. }
  2343. // Optional item
  2344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2345. {
  2346. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2347. }
  2348. else
  2349. {
  2350. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2351. }
  2352. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2353. {
  2354. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2355. }
  2356. else
  2357. {
  2358. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2359. }
  2360. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2361. {
  2362. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2363. }
  2364. else
  2365. {
  2366. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2367. }
  2368. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2369. {
  2370. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2371. }
  2372. else
  2373. {
  2374. defaultTxProfile.TransactionId = -1;
  2375. }
  2376. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2377. {
  2378. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2379. }
  2380. else
  2381. {
  2382. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2383. }
  2384. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2385. {
  2386. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2387. }
  2388. else
  2389. {
  2390. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2391. }
  2392. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2393. {
  2394. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2395. }
  2396. else
  2397. {
  2398. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2399. }
  2400. }
  2401. }
  2402. }
  2403. json_object_put(obj);
  2404. }
  2405. fclose(fp);
  2406. /*
  2407. if(defaultTxProfile.ChargingProfileId != -1)
  2408. {
  2409. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2410. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2411. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2412. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2413. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2414. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2415. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2416. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2417. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2418. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2419. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2420. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2421. {
  2422. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2423. {
  2424. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2425. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2426. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2427. }
  2428. }
  2429. }
  2430. else
  2431. DEBUG_INFO("TxDefaultProfile not found.\n");
  2432. DEBUG_INFO("------------------------------------\n");*/
  2433. }
  2434. // Search max profile
  2435. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2436. if((access(profileFileName, F_OK))!=-1)
  2437. {
  2438. fp = fopen(profileFileName, "r");
  2439. while(getline(&line, &len, fp) != -1)
  2440. {
  2441. json_object *obj = NULL;
  2442. obj = json_tokener_parse(line);
  2443. if(is_error(obj))
  2444. {
  2445. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2446. }
  2447. else
  2448. {
  2449. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2450. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2451. )
  2452. {
  2453. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2454. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2455. )
  2456. {
  2457. struct tm tmFrom, tmTo;
  2458. struct timeb tbFrom, tbTo;
  2459. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2460. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2461. {
  2462. tmFrom.tm_year -= 1900;
  2463. tmFrom.tm_mon -= 1;
  2464. tbFrom.time = mktime(&tmFrom);
  2465. tmTo.tm_year -= 1900;
  2466. tmTo.tm_mon -= 1;
  2467. tbTo.time = mktime(&tmTo);
  2468. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2469. {
  2470. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2471. {
  2472. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2473. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2474. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2475. }
  2476. if(maxProfile.ChargingProfileId == -1)
  2477. DEBUG_INFO("MaxProfile found.\n");
  2478. else
  2479. DEBUG_INFO("MaxProfile updated.\n");
  2480. // Required item
  2481. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2482. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2483. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2484. if(isUnitA)
  2485. {
  2486. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2487. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2488. {
  2489. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2490. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2491. 3:
  2492. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2493. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2494. }
  2495. }
  2496. else
  2497. {
  2498. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2499. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2500. {
  2501. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2502. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2503. 3:
  2504. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2505. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2506. }
  2507. }
  2508. // Optional item
  2509. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2510. {
  2511. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2512. }
  2513. else
  2514. {
  2515. sprintf((char*)maxProfile.ValidFrom, " ");
  2516. }
  2517. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2518. {
  2519. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2520. }
  2521. else
  2522. {
  2523. sprintf((char*)maxProfile.ValidTo, " ");
  2524. }
  2525. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2526. {
  2527. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2528. }
  2529. else
  2530. {
  2531. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2532. }
  2533. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2534. {
  2535. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2536. }
  2537. else
  2538. {
  2539. maxProfile.TransactionId = -1;
  2540. }
  2541. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2542. {
  2543. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2544. }
  2545. else
  2546. {
  2547. maxProfile.ChargingSchedule.Duration = 86400;
  2548. }
  2549. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2550. {
  2551. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2552. }
  2553. else
  2554. {
  2555. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2556. }
  2557. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2558. {
  2559. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2560. }
  2561. else
  2562. {
  2563. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2564. }
  2565. }
  2566. }
  2567. }
  2568. else
  2569. {
  2570. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2571. {
  2572. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2575. }
  2576. if(maxProfile.ChargingProfileId == -1)
  2577. DEBUG_INFO("MaxProfile found.\n");
  2578. else
  2579. DEBUG_INFO("MaxProfile updated.\n");
  2580. // Required item
  2581. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2582. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2583. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2584. if(isUnitA)
  2585. {
  2586. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2587. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2588. {
  2589. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2590. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2591. 3:
  2592. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2593. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2594. }
  2595. }
  2596. else
  2597. {
  2598. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2599. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2600. {
  2601. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2602. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2603. 3:
  2604. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2605. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2606. }
  2607. }
  2608. // Optional item
  2609. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2610. {
  2611. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2612. }
  2613. else
  2614. {
  2615. sprintf((char*)maxProfile.ValidFrom, " ");
  2616. }
  2617. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2618. {
  2619. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2620. }
  2621. else
  2622. {
  2623. sprintf((char*)maxProfile.ValidTo, " ");
  2624. }
  2625. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2626. {
  2627. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2628. }
  2629. else
  2630. {
  2631. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2632. }
  2633. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2634. {
  2635. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2636. }
  2637. else
  2638. {
  2639. maxProfile.TransactionId = -1;
  2640. }
  2641. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2642. {
  2643. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2644. }
  2645. else
  2646. {
  2647. maxProfile.ChargingSchedule.Duration = 86400;
  2648. }
  2649. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2650. {
  2651. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2652. }
  2653. else
  2654. {
  2655. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2656. }
  2657. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2658. {
  2659. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2660. }
  2661. else
  2662. {
  2663. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2664. }
  2665. }
  2666. }
  2667. }
  2668. json_object_put(obj);
  2669. }
  2670. fclose(fp);
  2671. /*
  2672. if(maxProfile.ChargingProfileId !=-1)
  2673. {
  2674. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2675. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2676. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2677. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2678. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2679. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2680. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2681. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2682. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2683. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2684. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2685. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2686. {
  2687. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2688. {
  2689. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2690. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2691. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2692. }
  2693. }
  2694. }
  2695. else
  2696. DEBUG_INFO("MaxProfile not found.\n");
  2697. DEBUG_INFO("------------------------------------\n");*/
  2698. }
  2699. /*
  2700. * Align found profile start schedule & periods
  2701. */
  2702. //DEBUG_INFO("====================================\n");
  2703. /*
  2704. // For local test usage, force modify found profile start schedule info
  2705. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  2706. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  2707. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  2708. */
  2709. if(txProfile.ChargingProfileId != -1)
  2710. {
  2711. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2712. {
  2713. if(txProfile.ChargingSchedule.Duration != -1)
  2714. {
  2715. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2716. 0:
  2717. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2718. }
  2719. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2720. {
  2721. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2722. {
  2723. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2724. 0:
  2725. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2726. if(idxPeriod > 0)
  2727. {
  2728. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2729. {
  2730. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2731. }
  2732. }
  2733. }
  2734. }
  2735. }
  2736. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2737. {
  2738. if(txProfile.ChargingSchedule.Duration != -1)
  2739. {
  2740. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2741. 0:
  2742. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2743. }
  2744. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2745. {
  2746. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2747. {
  2748. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2749. 0:
  2750. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2751. if(idxPeriod > 0)
  2752. {
  2753. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2754. {
  2755. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2756. }
  2757. }
  2758. }
  2759. }
  2760. }
  2761. else
  2762. {
  2763. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2764. {
  2765. if(txProfile.ChargingSchedule.Duration != -1)
  2766. {
  2767. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2768. 0:
  2769. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2770. }
  2771. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2772. {
  2773. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2774. {
  2775. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2776. 0:
  2777. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2778. if(idxPeriod > 0)
  2779. {
  2780. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2781. {
  2782. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2783. }
  2784. }
  2785. }
  2786. }
  2787. }
  2788. else
  2789. {
  2790. if(txProfile.ChargingSchedule.Duration != -1)
  2791. {
  2792. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2793. 0:
  2794. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2795. }
  2796. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2797. {
  2798. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2799. {
  2800. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2801. 0:
  2802. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2803. if(idxPeriod > 0)
  2804. {
  2805. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2806. {
  2807. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2808. }
  2809. }
  2810. }
  2811. }
  2812. }
  2813. }
  2814. /*
  2815. DEBUG_INFO("txProfile after align.\n");
  2816. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2817. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2818. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2819. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2820. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2821. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2822. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2823. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2824. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2825. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2826. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2827. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2828. {
  2829. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2830. {
  2831. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2832. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2833. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2834. }
  2835. }*/
  2836. }
  2837. if(defaultTxProfile.ChargingProfileId != -1)
  2838. {
  2839. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2840. {
  2841. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2842. {
  2843. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2844. 0:
  2845. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2846. }
  2847. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2848. {
  2849. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2850. {
  2851. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2852. 0:
  2853. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2854. if(idxPeriod > 0)
  2855. {
  2856. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2857. {
  2858. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2859. }
  2860. }
  2861. }
  2862. }
  2863. }
  2864. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2865. {
  2866. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2867. {
  2868. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2869. 0:
  2870. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2871. }
  2872. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2873. {
  2874. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2875. {
  2876. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2877. 0:
  2878. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2879. if(idxPeriod > 0)
  2880. {
  2881. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2882. {
  2883. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2884. }
  2885. }
  2886. }
  2887. }
  2888. }
  2889. else
  2890. {
  2891. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2892. {
  2893. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2894. {
  2895. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2896. 0:
  2897. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2898. }
  2899. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2900. {
  2901. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2902. {
  2903. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2904. 0:
  2905. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2906. if(idxPeriod > 0)
  2907. {
  2908. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2909. {
  2910. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2911. }
  2912. }
  2913. }
  2914. }
  2915. }
  2916. else
  2917. {
  2918. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2919. {
  2920. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2921. 0:
  2922. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2923. }
  2924. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2925. {
  2926. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2927. {
  2928. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2929. 0:
  2930. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2931. if(idxPeriod > 0)
  2932. {
  2933. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2934. {
  2935. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2936. }
  2937. }
  2938. }
  2939. }
  2940. }
  2941. }
  2942. /*
  2943. DEBUG_INFO("defaultTxProfile after align.\n");
  2944. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2945. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2946. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2947. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2948. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2949. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2950. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2951. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2952. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2953. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2954. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2955. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2956. {
  2957. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2958. {
  2959. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2960. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2961. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2962. }
  2963. }
  2964. DEBUG_INFO("------------------------------------\n");*/
  2965. }
  2966. if(maxProfile.ChargingProfileId != -1)
  2967. {
  2968. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2969. {
  2970. if(maxProfile.ChargingSchedule.Duration != -1)
  2971. {
  2972. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2973. 0:
  2974. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2975. }
  2976. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2977. {
  2978. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2979. {
  2980. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2981. 0:
  2982. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2983. if(idxPeriod > 0)
  2984. {
  2985. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2986. {
  2987. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2988. }
  2989. }
  2990. }
  2991. }
  2992. }
  2993. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2994. {
  2995. if(maxProfile.ChargingSchedule.Duration != -1)
  2996. {
  2997. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2998. 0:
  2999. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3000. }
  3001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3002. {
  3003. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3004. {
  3005. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3006. 0:
  3007. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3008. if(idxPeriod > 0)
  3009. {
  3010. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3011. {
  3012. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3013. }
  3014. }
  3015. }
  3016. }
  3017. }
  3018. else
  3019. {
  3020. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3021. {
  3022. if(maxProfile.ChargingSchedule.Duration != -1)
  3023. {
  3024. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3025. 0:
  3026. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3027. }
  3028. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3029. {
  3030. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3031. {
  3032. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3033. 0:
  3034. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3035. if(idxPeriod > 0)
  3036. {
  3037. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3038. {
  3039. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3040. }
  3041. }
  3042. }
  3043. }
  3044. }
  3045. else
  3046. {
  3047. if(maxProfile.ChargingSchedule.Duration != -1)
  3048. {
  3049. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3050. 0:
  3051. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3052. }
  3053. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3054. {
  3055. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3056. {
  3057. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3058. 0:
  3059. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3060. if(idxPeriod > 0)
  3061. {
  3062. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3063. {
  3064. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3065. }
  3066. }
  3067. }
  3068. }
  3069. }
  3070. }
  3071. /*
  3072. DEBUG_INFO("MaxProfile after align.\n");
  3073. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3074. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3075. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3076. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3077. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3078. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3079. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3080. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3081. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3082. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3083. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3084. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3085. {
  3086. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3087. {
  3088. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3089. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3090. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3091. }
  3092. }
  3093. DEBUG_INFO("------------------------------------\n");*/
  3094. }
  3095. /*
  3096. * Merge to conposite schedule
  3097. */
  3098. //DEBUG_INFO("====================================\n");
  3099. // Find each profile period quantity
  3100. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3101. {
  3102. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3103. limitMax = idx+1;
  3104. }
  3105. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3106. {
  3107. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3108. limitDef = idx+1;
  3109. }
  3110. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3111. {
  3112. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3113. limitTx = idx+1;
  3114. }
  3115. // TxProfile found, composite schedule based on it
  3116. if(txProfile.ChargingProfileId != -1)
  3117. {
  3118. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3119. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3120. {
  3121. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3122. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3123. (txProfile.ChargingSchedule.Duration > 0))
  3124. {
  3125. if(maxProfile.ChargingProfileId != -1)
  3126. {
  3127. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3128. {
  3129. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3130. {
  3131. if((maxProfile.ChargingSchedule.Duration > 0))
  3132. {
  3133. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3134. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3135. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3136. }
  3137. else
  3138. {
  3139. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3140. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3141. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3142. }
  3143. }
  3144. if(idxMaxPeriod == (limitMax-1))
  3145. {
  3146. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3147. {
  3148. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3149. {
  3150. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3151. compositePeriodIdx++;
  3152. }
  3153. else
  3154. {
  3155. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3156. }
  3157. }
  3158. }
  3159. }
  3160. }
  3161. else
  3162. {
  3163. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3164. {
  3165. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3166. compositePeriodIdx++;
  3167. }
  3168. else
  3169. {
  3170. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3171. }
  3172. }
  3173. }
  3174. if(idxTxPeriod == (limitTx-1))
  3175. {
  3176. if(defaultTxProfile.ChargingProfileId != -1)
  3177. {
  3178. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3179. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3180. {
  3181. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3182. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3183. (defaultTxProfile.ChargingSchedule.Duration>0))
  3184. {
  3185. if(maxProfile.ChargingProfileId != -1)
  3186. {
  3187. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3188. {
  3189. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3190. {
  3191. if((maxProfile.ChargingSchedule.Duration > 0))
  3192. {
  3193. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3194. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3195. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3196. }
  3197. else
  3198. {
  3199. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3200. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3201. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3202. }
  3203. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3204. {
  3205. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3206. {
  3207. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3208. compositePeriodIdx++;
  3209. }
  3210. else
  3211. {
  3212. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3213. }
  3214. }
  3215. // Delete duplicate period
  3216. if(compositePeriodIdx > 1)
  3217. {
  3218. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3219. {
  3220. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3221. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3222. compositePeriodIdx -= 1;
  3223. }
  3224. }
  3225. }
  3226. else
  3227. {
  3228. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3229. {
  3230. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3231. compositePeriodIdx++;
  3232. }
  3233. else
  3234. {
  3235. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3236. }
  3237. break;
  3238. }
  3239. }
  3240. }
  3241. else
  3242. {
  3243. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3244. {
  3245. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3246. compositePeriodIdx++;
  3247. }
  3248. else
  3249. {
  3250. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3251. }
  3252. }
  3253. }
  3254. }
  3255. }
  3256. }
  3257. }
  3258. }
  3259. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3260. else if(defaultTxProfile.ChargingProfileId != -1)
  3261. {
  3262. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3263. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3264. {
  3265. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3266. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3267. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3268. {
  3269. if(maxProfile.ChargingProfileId != -1)
  3270. {
  3271. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3272. {
  3273. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3274. {
  3275. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3276. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3277. if((maxProfile.ChargingSchedule.Duration > 0))
  3278. {
  3279. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3280. }
  3281. else
  3282. {
  3283. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3284. }
  3285. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3286. {
  3287. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3288. {
  3289. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3290. compositePeriodIdx++;
  3291. }
  3292. else
  3293. {
  3294. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3295. }
  3296. }
  3297. // Delete duplicate period
  3298. if(compositePeriodIdx > 1)
  3299. {
  3300. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3301. {
  3302. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3303. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3304. compositePeriodIdx -= 1;
  3305. }
  3306. }
  3307. }
  3308. else
  3309. {
  3310. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3311. {
  3312. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3313. compositePeriodIdx++;
  3314. }
  3315. else
  3316. {
  3317. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3318. }
  3319. break;
  3320. }
  3321. }
  3322. }
  3323. else
  3324. {
  3325. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3326. {
  3327. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3328. compositePeriodIdx++;
  3329. }
  3330. else
  3331. {
  3332. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3333. }
  3334. }
  3335. }
  3336. }
  3337. }
  3338. // Fill other period by MaxProfile
  3339. if(maxProfile.ChargingProfileId != -1)
  3340. {
  3341. if(compositePeriodIdx==0)
  3342. {
  3343. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3344. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3345. {
  3346. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3347. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3348. (maxProfile.ChargingSchedule.Duration > 0))
  3349. {
  3350. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3351. {
  3352. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3353. compositePeriodIdx++;
  3354. }
  3355. else
  3356. {
  3357. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3358. }
  3359. }
  3360. }
  3361. }
  3362. else
  3363. {
  3364. int lastCompositePeriodIdx = compositePeriodIdx;
  3365. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3366. {
  3367. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3368. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3369. (maxProfile.ChargingSchedule.Duration > 0))
  3370. {
  3371. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3372. {
  3373. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3374. {
  3375. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3376. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3377. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3378. }
  3379. else
  3380. {
  3381. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3382. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3383. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3384. }
  3385. }
  3386. if(tmpPeriod.Limit != -1)
  3387. {
  3388. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3389. {
  3390. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3391. {
  3392. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3393. compositePeriodIdx++;
  3394. }
  3395. else
  3396. {
  3397. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3398. }
  3399. }
  3400. // Delete duplicate period
  3401. if(compositePeriodIdx > 1)
  3402. {
  3403. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3404. {
  3405. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3406. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3407. compositePeriodIdx -= 1;
  3408. }
  3409. }
  3410. }
  3411. }
  3412. }
  3413. }
  3414. }
  3415. compositeProfile.ChargingSchedule.Duration = durationReq;
  3416. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3417. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3418. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3419. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3420. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3421. {
  3422. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3423. {
  3424. compositeProfile.ChargingProfileId = 1;
  3425. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3426. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3427. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3428. }
  3429. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3430. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3431. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3432. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3433. }
  3434. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3435. if(line)
  3436. free(line);
  3437. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3438. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3439. }
  3440. //==========================================
  3441. // Init all share memory
  3442. //==========================================
  3443. int InitShareMemory()
  3444. {
  3445. int result = PASS;
  3446. int MeterSMId;
  3447. //creat ShmSysConfigAndInfo
  3448. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3449. {
  3450. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3451. result = FAIL;
  3452. }
  3453. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3454. {
  3455. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3456. result = FAIL;
  3457. }
  3458. else
  3459. {}
  3460. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3461. {
  3462. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3463. result = FAIL;
  3464. }
  3465. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3466. {
  3467. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3468. result = FAIL;
  3469. }
  3470. else
  3471. {}
  3472. //creat ShmPsuData
  3473. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3474. {
  3475. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3476. result = FAIL;
  3477. }
  3478. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3479. {
  3480. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3481. result = FAIL;
  3482. }
  3483. else
  3484. {}
  3485. //link ShmOCPP16Data
  3486. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3487. {
  3488. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3489. result = FAIL;
  3490. }
  3491. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3492. {
  3493. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3494. result = FAIL;
  3495. }
  3496. else
  3497. {}
  3498. //creat ShmOCPP16DataPH
  3499. if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3500. {
  3501. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3502. result = FAIL;
  3503. }
  3504. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3505. {
  3506. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3507. result = FAIL;
  3508. }
  3509. else
  3510. {}
  3511. /****************************** For Initial Settings************************************************/
  3512. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3513. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3514. // allocate Configuration memory address
  3515. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3516. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3517. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3518. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3519. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3520. //offline MeterValue Interval
  3521. TempMeterValueInterval = 0;
  3522. return result;
  3523. }
  3524. int ProcessShareMemory()
  3525. {
  3526. int result = PASS;
  3527. if(InitShareMemory() == FAIL)
  3528. {
  3529. DEBUG_ERROR("InitShareMemory NG\n");
  3530. if(ShmStatusCodeData!=NULL)
  3531. {
  3532. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3533. }
  3534. result = FAIL;
  3535. }
  3536. // Model name parsing
  3537. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3538. {
  3539. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3540. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3541. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3542. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3543. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3544. ) // 'D' means DC
  3545. {
  3546. // DO series
  3547. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3548. {
  3549. gunTotalNumber += 1;
  3550. gunType[gun_index] = GUN_TYPE_DO;
  3551. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3552. {
  3553. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3554. {
  3555. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3556. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3557. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3558. }
  3559. }
  3560. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3561. {
  3562. case Gun_Type_Chademo:
  3563. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3564. break;
  3565. case Gun_Type_CCS_2:
  3566. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3567. break;
  3568. case Gun_Type_GB:
  3569. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3570. break;
  3571. case Gun_Type_AC:
  3572. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3573. break;
  3574. default:
  3575. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3576. break;
  3577. }
  3578. }
  3579. }
  3580. else
  3581. {
  3582. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3583. {
  3584. gunTotalNumber += 1;
  3585. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3586. {
  3587. case Gun_Type_Chademo:
  3588. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3589. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3590. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  3591. {
  3592. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  3593. {
  3594. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3595. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3596. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  3597. }
  3598. }
  3599. break;
  3600. case Gun_Type_CCS_2:
  3601. gunType[gun_index] = GUN_TYPE_CCS;
  3602. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3603. for (int index = 0; index < CCS_QUANTITY; index++)
  3604. {
  3605. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  3606. {
  3607. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3608. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3609. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  3610. }
  3611. }
  3612. break;
  3613. case Gun_Type_GB:
  3614. gunType[gun_index] = GUN_TYPE_GBT;
  3615. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3616. for (int index = 0; index < GB_QUANTITY; index++)
  3617. {
  3618. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  3619. {
  3620. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3621. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3622. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  3623. }
  3624. }
  3625. break;
  3626. case Gun_Type_AC:
  3627. gunType[gun_index] = GUN_TYPE_AC;
  3628. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3629. for (int index = 0; index < AC_QUANTITY; index++)
  3630. {
  3631. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  3632. {
  3633. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3634. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3635. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  3636. }
  3637. }
  3638. break;
  3639. default:
  3640. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3641. break;
  3642. }
  3643. }
  3644. }
  3645. }
  3646. else
  3647. {
  3648. DEBUG_ERROR("Model name parsing fail.\n");
  3649. result = FAIL;
  3650. }
  3651. if(result != PASS)sleep(5);
  3652. return result;
  3653. }
  3654. void checkRemoteStart(uint8_t connectorIdInt)
  3655. {
  3656. uint8_t tempIndex;
  3657. int result = PASS;
  3658. char cmdBuf[512];
  3659. //check Transaction active
  3660. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3661. {
  3662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3663. {
  3664. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3665. }
  3666. else
  3667. {
  3668. tempIndex = connectorIdInt -1;
  3669. }
  3670. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3671. {
  3672. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3673. {
  3674. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3675. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3676. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3677. {
  3678. //Reserved
  3679. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3680. }
  3681. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3682. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3683. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3684. {
  3685. //Reserved
  3686. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3687. result = FAIL;
  3688. goto end;
  3689. }
  3690. else
  3691. {
  3692. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3693. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3694. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3695. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3696. {
  3697. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3698. result = FAIL;
  3699. goto end;
  3700. }
  3701. }//END FOR ELSE
  3702. }
  3703. }// END FOR CHAdeMO_QUANTITY
  3704. }
  3705. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3706. {
  3707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3708. {
  3709. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3710. }
  3711. else
  3712. {
  3713. tempIndex = connectorIdInt -1;
  3714. }
  3715. for (int index = 0; index < CCS_QUANTITY; index++)
  3716. {
  3717. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3718. {
  3719. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3720. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3721. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3722. {
  3723. //Reserved
  3724. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3725. }
  3726. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3727. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3728. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3729. {
  3730. //Reserved
  3731. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3732. result = FAIL;
  3733. goto end;
  3734. }
  3735. else
  3736. {
  3737. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3738. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3739. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3740. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3741. {
  3742. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3743. result = FAIL;
  3744. goto end;
  3745. }
  3746. }// END FOR ELSE
  3747. }
  3748. }// END FOR CCS_QUANTITY
  3749. }
  3750. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3751. {
  3752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3753. {
  3754. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3755. }
  3756. else
  3757. {
  3758. tempIndex = connectorIdInt -1;
  3759. }
  3760. for (int index = 0; index < GB_QUANTITY; index++)
  3761. {
  3762. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3763. {
  3764. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3765. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3766. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3767. {
  3768. //Reserved
  3769. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3770. }
  3771. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3772. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3773. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3774. {
  3775. //Reserved
  3776. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3777. result = FAIL;
  3778. goto end;
  3779. }
  3780. else
  3781. {
  3782. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3783. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3784. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3785. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3786. {
  3787. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3788. result = FAIL;
  3789. goto end;
  3790. }
  3791. }// END FOR ELSE
  3792. }
  3793. } // END FOR GB_QUANTITY
  3794. }
  3795. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3796. {
  3797. tempIndex = connectorIdInt -1;
  3798. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3799. {
  3800. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3801. {
  3802. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3803. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3804. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3805. {
  3806. //Reserved
  3807. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3808. }
  3809. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3810. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3811. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3812. {
  3813. //Reserved
  3814. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3815. result = FAIL;
  3816. goto end;
  3817. }
  3818. else
  3819. {
  3820. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3821. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3822. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3823. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3824. {
  3825. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3826. result = FAIL;
  3827. goto end;
  3828. }
  3829. }// END FOR ELSE
  3830. }
  3831. } // END FOR GB_QUANTITY
  3832. }
  3833. else
  3834. {
  3835. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3836. {
  3837. tempIndex = 2;
  3838. }
  3839. else
  3840. {
  3841. tempIndex = connectorIdInt -1;
  3842. }
  3843. for (int index = 0; index < AC_QUANTITY; index++)
  3844. {
  3845. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3846. {
  3847. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3848. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3849. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3850. {
  3851. //Reserved
  3852. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3853. }
  3854. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3855. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3856. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3857. {
  3858. //Reserved
  3859. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3860. result = FAIL;
  3861. goto end;
  3862. }
  3863. else
  3864. {
  3865. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3866. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3867. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3868. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3869. {
  3870. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3871. result = FAIL;
  3872. goto end;
  3873. }
  3874. }//END FOR ELSE
  3875. }
  3876. }// END FOR AC_QUANTITY
  3877. }
  3878. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3879. {
  3880. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3881. {
  3882. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3883. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3884. {
  3885. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3886. system(cmdBuf);
  3887. }
  3888. }
  3889. else
  3890. {
  3891. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3892. result = FAIL;
  3893. }
  3894. }
  3895. end:
  3896. if(result == PASS)
  3897. {
  3898. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3899. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3900. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3901. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3902. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3903. }
  3904. }
  3905. void CheckSystemValue(void)
  3906. {
  3907. char filenmae[100]={0};
  3908. char str[100]={0};
  3909. int tempIndex = 0;
  3910. //===============================
  3911. // send Heartbeat
  3912. //===============================
  3913. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3914. {
  3915. //parameter for test
  3916. sendHeartbeatRequest(0);
  3917. //==============================================
  3918. // Reset Waiting Time
  3919. //==============================================
  3920. HeartBeatWithNOResponse += 2;
  3921. }
  3922. //===============================
  3923. // Credit deduct report
  3924. //===============================
  3925. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3926. {
  3927. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3928. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3929. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3930. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3931. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3932. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3933. }
  3934. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3935. {
  3936. OCPP_query_deduct_info();
  3937. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3938. }
  3939. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3940. {
  3941. // ClockAlign MeterValue
  3942. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3943. {
  3944. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3945. {
  3946. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3947. {
  3948. tempIndex = ((gun_index==2) ? 1: 0);
  3949. }
  3950. else
  3951. {
  3952. tempIndex = gun_index;
  3953. }
  3954. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3955. {
  3956. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3957. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3958. {
  3959. reqClockAlignMeter[gun_index] = 1;
  3960. }
  3961. }// End for CHAdeMO
  3962. }
  3963. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3964. {
  3965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3966. {
  3967. tempIndex = ((gun_index==2) ? 1: 0);
  3968. }
  3969. else
  3970. {
  3971. tempIndex = gun_index;
  3972. }
  3973. for (int index = 0; index < CCS_QUANTITY; index++)
  3974. {
  3975. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3976. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3977. {
  3978. reqClockAlignMeter[gun_index] = 1;
  3979. }
  3980. } // End for CCS
  3981. }
  3982. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3983. {
  3984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3985. {
  3986. tempIndex = ((gun_index==2) ? 1: 0);
  3987. }
  3988. else
  3989. {
  3990. tempIndex = gun_index;
  3991. }
  3992. for (int index = 0; index < GB_QUANTITY; index++)
  3993. {
  3994. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3995. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3996. {
  3997. reqClockAlignMeter[gun_index] = 1;
  3998. }
  3999. }// End for GB
  4000. }
  4001. else if(gunType[gun_index] == GUN_TYPE_DO)
  4002. {
  4003. tempIndex = gun_index;
  4004. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4005. {
  4006. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4007. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4008. {
  4009. reqClockAlignMeter[gun_index] = 1;
  4010. }
  4011. }
  4012. }
  4013. else
  4014. {
  4015. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4016. {
  4017. tempIndex = 2;
  4018. }
  4019. else
  4020. {
  4021. tempIndex = gun_index;
  4022. }
  4023. for (int index = 0; index < AC_QUANTITY; index++)
  4024. {
  4025. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4026. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4027. {
  4028. reqClockAlignMeter[gun_index] = 1;
  4029. }
  4030. }//End for AC
  4031. }
  4032. }
  4033. }
  4034. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4035. {
  4036. //==========================================
  4037. // Check remote start without connector id
  4038. //==========================================
  4039. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  4040. {
  4041. int connectorIdInt = -1;
  4042. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4043. {
  4044. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4045. {
  4046. connectorIdInt = (gun_index+1);
  4047. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4048. checkRemoteStart(connectorIdInt);
  4049. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4050. break;
  4051. }
  4052. }
  4053. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4054. {
  4055. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4056. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4057. }
  4058. }
  4059. //==========================================
  4060. // csu trigger DataTransferReq
  4061. //==========================================
  4062. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4063. {
  4064. sendDataTransferRequest(gun_index);
  4065. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4066. }
  4067. //===============================
  4068. // CSU Trigger Authorize Request
  4069. //===============================
  4070. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4071. {
  4072. sendAuthorizeRequest(0);
  4073. authorizeRetryTimes = authorizeRetryTimes + 1;
  4074. if(authorizeRetryTimes < 3)
  4075. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4076. }
  4077. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4078. {
  4079. authorizeRetryTimes = 0;
  4080. SetOcppConnStatus(FALSE);
  4081. server_sign = FALSE;
  4082. }
  4083. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0)&& (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1))
  4084. {
  4085. sendAuthorizeRequest(0);
  4086. }
  4087. //==============================================
  4088. // Charger start transaction
  4089. //==============================================
  4090. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4091. {
  4092. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4093. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4094. sendStartTransactionRequest(gun_index);
  4095. refreshStartTimer(&clientTime.StartTransaction);
  4096. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4097. //storeTempStopTransaction(gun_index);
  4098. }
  4099. //==============================================
  4100. // Charger stop transaction
  4101. //==============================================
  4102. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4103. {
  4104. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4105. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4106. sendStopTransactionRequest(gun_index);
  4107. refreshStartTimer(&clientTime.StopTransaction);
  4108. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4109. }
  4110. //==============================================
  4111. // Charger status report
  4112. //==============================================
  4113. //--- Check Mode Change ---//
  4114. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4115. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4116. {
  4117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4118. {
  4119. tempIndex = ((gun_index==2) ? 1: 0);
  4120. }
  4121. else
  4122. {
  4123. tempIndex = gun_index;
  4124. }
  4125. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4126. {
  4127. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4128. {
  4129. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4130. {
  4131. // Sent unplug message for California pricing logic
  4132. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4133. {
  4134. uint8_t ts[36];
  4135. getNowDatetime(ts);
  4136. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4137. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4138. if(strcmp((char*)dmsVersion, "2.0")==0)
  4139. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4140. else
  4141. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4142. sendUnplugByDataTransferRequest(gun_index);
  4143. interLock.isSentUnplug[gun_index] = 1;
  4144. }
  4145. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4146. {
  4147. interLock.isSentUnplug[gun_index] = 0;
  4148. }
  4149. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4150. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4151. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4152. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4153. {
  4154. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4155. if((access(filenmae,F_OK))!=-1)
  4156. {
  4157. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4158. sprintf(str,"rm -f %s",filenmae);
  4159. system(str);
  4160. }
  4161. }
  4162. }
  4163. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4164. #if 1 // for TempStopTransaction
  4165. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4166. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4167. {
  4168. checkTempStopTransaction(gun_index);
  4169. }
  4170. #endif
  4171. }
  4172. }
  4173. }
  4174. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4175. {
  4176. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4177. {
  4178. tempIndex = ((gun_index==2) ? 1: 0);
  4179. }
  4180. else
  4181. {
  4182. tempIndex = gun_index;
  4183. }
  4184. for (int index = 0; index < CCS_QUANTITY; index++)
  4185. {
  4186. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4187. {
  4188. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  4189. {
  4190. // Sent unplug message for California pricing logic
  4191. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4192. {
  4193. uint8_t ts[36];
  4194. getNowDatetime(ts);
  4195. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4196. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4197. if(strcmp((char*)dmsVersion, "2.0")==0)
  4198. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4199. else
  4200. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4201. sendUnplugByDataTransferRequest(gun_index);
  4202. interLock.isSentUnplug[gun_index] = 1;
  4203. }
  4204. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4205. {
  4206. interLock.isSentUnplug[gun_index] = 0;
  4207. }
  4208. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4209. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4210. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4211. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4212. {
  4213. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4214. if((access(filenmae,F_OK))!=-1)
  4215. {
  4216. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4217. sprintf(str,"rm -f %s",filenmae);
  4218. system(str);
  4219. }
  4220. }
  4221. }
  4222. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4223. #if 1 // for TempStopTransaction
  4224. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4225. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4226. {
  4227. checkTempStopTransaction(gun_index);
  4228. }
  4229. #endif
  4230. }
  4231. }
  4232. }
  4233. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4234. {
  4235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4236. {
  4237. tempIndex = ((gun_index==2) ? 1: 0);
  4238. }
  4239. else
  4240. {
  4241. tempIndex = gun_index;
  4242. }
  4243. for (int index = 0; index < GB_QUANTITY; index++)
  4244. {
  4245. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4246. {
  4247. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4248. {
  4249. // Sent unplug message for California pricing logic
  4250. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4251. {
  4252. uint8_t ts[36];
  4253. getNowDatetime(ts);
  4254. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4255. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4256. if(strcmp((char*)dmsVersion, "2.0")==0)
  4257. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4258. else
  4259. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4260. sendUnplugByDataTransferRequest(gun_index);
  4261. interLock.isSentUnplug[gun_index] = 1;
  4262. }
  4263. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4264. {
  4265. interLock.isSentUnplug[gun_index] = 0;
  4266. }
  4267. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4268. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4269. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4270. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4271. {
  4272. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4273. if((access(filenmae,F_OK))!=-1)
  4274. {
  4275. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4276. sprintf(str,"rm -f %s",filenmae);
  4277. system(str);
  4278. }
  4279. }
  4280. }
  4281. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4282. #if 1 // for TempStopTransaction
  4283. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4284. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4285. {
  4286. checkTempStopTransaction(gun_index);
  4287. }
  4288. #endif
  4289. }
  4290. }
  4291. }
  4292. else if(gunType[gun_index] == GUN_TYPE_DO)
  4293. {
  4294. tempIndex = gun_index;
  4295. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4296. {
  4297. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4298. {
  4299. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4300. {
  4301. // Sent unplug message for California pricing logic
  4302. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4303. {
  4304. uint8_t ts[36];
  4305. getNowDatetime(ts);
  4306. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4307. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4308. if(strcmp((char*)dmsVersion, "2.0")==0)
  4309. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4310. else
  4311. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4312. sendUnplugByDataTransferRequest(gun_index);
  4313. interLock.isSentUnplug[gun_index] = 1;
  4314. }
  4315. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4316. {
  4317. interLock.isSentUnplug[gun_index] = 0;
  4318. }
  4319. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4320. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4321. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4322. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  4323. {
  4324. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4325. if((access(filenmae,F_OK))!=-1)
  4326. {
  4327. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4328. sprintf(str,"rm -f %s",filenmae);
  4329. system(str);
  4330. }
  4331. }
  4332. }
  4333. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4334. #if 1 // for TempStopTransaction
  4335. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4336. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4337. {
  4338. checkTempStopTransaction(gun_index);
  4339. }
  4340. #endif
  4341. }
  4342. }
  4343. }
  4344. else
  4345. {
  4346. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4347. {
  4348. tempIndex = 2;
  4349. }
  4350. else
  4351. {
  4352. tempIndex = gun_index;
  4353. }
  4354. for (int index = 0; index < AC_QUANTITY; index++)
  4355. {
  4356. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4357. {
  4358. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4359. {
  4360. // Sent unplug message for California pricing logic
  4361. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4362. {
  4363. uint8_t ts[36];
  4364. getNowDatetime(ts);
  4365. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4366. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4367. if(strcmp((char*)dmsVersion, "2.0")==0)
  4368. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4369. else
  4370. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4371. sendUnplugByDataTransferRequest(gun_index);
  4372. interLock.isSentUnplug[gun_index] = 1;
  4373. }
  4374. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4375. {
  4376. interLock.isSentUnplug[gun_index] = 0;
  4377. }
  4378. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4379. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4380. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4381. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4382. {
  4383. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4384. if((access(filenmae,F_OK))!=-1)
  4385. {
  4386. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4387. sprintf(str,"rm -f %s",filenmae);
  4388. system(str);
  4389. }
  4390. }
  4391. }
  4392. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4393. #if 1 // for TempStopTransaction
  4394. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4395. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4396. {
  4397. checkTempStopTransaction(gun_index);
  4398. }
  4399. #endif
  4400. }
  4401. }// END
  4402. }
  4403. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4404. (
  4405. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4406. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4407. )
  4408. )
  4409. {
  4410. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4411. sendStatusNotificationRequest(gun_index);
  4412. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4413. }
  4414. //==============================================
  4415. // TCCI reader status report
  4416. //==============================================
  4417. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4418. {
  4419. reportReaderStatus(gun_index);
  4420. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4421. }
  4422. //==============================================
  4423. // CSU Trigger or timer timeout refresh Smart Charging Profile
  4424. //==============================================
  4425. if((ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  4426. ((cpinitateMsg.bits[gun_index].isOnCharging) && (atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData) > 0) && (getDiffSecNow(clientTime.CharingProfileRefresh[gun_index]) > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData))))
  4427. {
  4428. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4429. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4430. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  4431. }
  4432. //==============================================
  4433. // Meter report
  4434. //==============================================
  4435. // Trigger MeterValue
  4436. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4437. {
  4438. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4439. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4440. }
  4441. // Clock-aligned Meter value
  4442. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4443. {
  4444. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4445. reqClockAlignMeter[gun_index] = 0;
  4446. }
  4447. // Sample period MeterValue
  4448. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4449. {
  4450. //check Transaction active
  4451. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4452. {
  4453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4454. {
  4455. tempIndex = ((gun_index==2) ? 1: 0);
  4456. }
  4457. else
  4458. {
  4459. tempIndex = gun_index;
  4460. }
  4461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4462. {
  4463. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4464. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4465. {
  4466. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4467. {
  4468. reqSampleMeter[gun_index] = 1;
  4469. }
  4470. }
  4471. }// End for CHAdeMO
  4472. }
  4473. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4474. {
  4475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4476. {
  4477. tempIndex = ((gun_index==2) ? 1: 0);
  4478. }
  4479. else
  4480. {
  4481. tempIndex = gun_index;
  4482. }
  4483. for (int index = 0; index < CCS_QUANTITY; index++)
  4484. {
  4485. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4486. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4487. {
  4488. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4489. {
  4490. reqSampleMeter[gun_index] = 1;
  4491. }
  4492. }
  4493. } // End for CCS
  4494. }
  4495. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4496. {
  4497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4498. {
  4499. tempIndex = ((gun_index==2) ? 1: 0);
  4500. }
  4501. else
  4502. {
  4503. tempIndex = gun_index;
  4504. }
  4505. for (int index = 0; index < GB_QUANTITY; index++)
  4506. {
  4507. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4508. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4509. {
  4510. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4511. {
  4512. reqSampleMeter[gun_index] = 1;
  4513. }
  4514. }
  4515. }// End for GB
  4516. }
  4517. else if(gunType[gun_index] == GUN_TYPE_DO)
  4518. {
  4519. tempIndex = gun_index;
  4520. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4521. {
  4522. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4523. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4524. {
  4525. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4526. {
  4527. reqSampleMeter[gun_index] = 1;
  4528. }
  4529. }
  4530. }
  4531. }
  4532. else
  4533. {
  4534. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4535. {
  4536. tempIndex = 2;
  4537. }
  4538. else
  4539. {
  4540. tempIndex = gun_index;
  4541. }
  4542. for (int index = 0; index < AC_QUANTITY; index++)
  4543. {
  4544. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4545. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4546. {
  4547. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4548. {
  4549. reqSampleMeter[gun_index] = 1;
  4550. }
  4551. }
  4552. }//End for AC
  4553. }
  4554. if(reqSampleMeter[gun_index] == 1)
  4555. {
  4556. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4557. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4558. //storeTempStopTransaction(gun_index);
  4559. reqSampleMeter[gun_index] = 0;
  4560. }
  4561. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4562. }
  4563. //==============================================
  4564. // Check Connector reserved
  4565. //==============================================
  4566. //===============================
  4567. // Check if Reserve is expired
  4568. //===============================
  4569. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4570. {
  4571. double diff_t;
  4572. struct tm tp;
  4573. // current time
  4574. time_t t = time(NULL);
  4575. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4576. tp.tm_isdst = -1;
  4577. time_t utc = mktime(&tp);
  4578. diff_t = difftime(utc, t);
  4579. if(diff_t <= 0)
  4580. {
  4581. DEBUG_INFO("reserve expired.\n");
  4582. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4583. }
  4584. }//END OF Check if Reserve is expired
  4585. //==========================================
  4586. // csu trigger FirmwareStatusNotificationReq
  4587. //==========================================
  4588. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4589. {
  4590. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4591. }
  4592. //==========================================
  4593. // csu trigger DiagnosticsStatusNotificationReq
  4594. //==========================================
  4595. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4596. {
  4597. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4598. }
  4599. //==========================================
  4600. // csu trigger CancelReservationConf
  4601. //==========================================
  4602. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4603. {
  4604. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4605. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4606. }
  4607. //==========================================
  4608. // csu trigger ChangeAvailabilityConf
  4609. //==========================================
  4610. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4611. {
  4612. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4613. }
  4614. //==========================================
  4615. // csu trigger UnlockConnectorConf
  4616. //==========================================
  4617. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4618. {
  4619. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4620. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4621. }
  4622. //==========================================
  4623. // csu trigger ReserveNowConf
  4624. //==========================================
  4625. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4626. {
  4627. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4628. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4629. }
  4630. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4631. {
  4632. sendSignCertificateRequest();
  4633. }
  4634. }
  4635. }
  4636. //==========================================
  4637. // send request routine
  4638. //==========================================
  4639. int sendAuthorizeRequest(int gun_index)
  4640. {
  4641. mtrace();
  4642. int result = FAIL;
  4643. char message[100]={0};
  4644. char guid[37];
  4645. char tempdata[65]={0};
  4646. DEBUG_INFO("sendAuthorizeRequest...\n");
  4647. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4648. //Local Authorize
  4649. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4650. {
  4651. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4652. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4653. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4654. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4655. result = PASS;
  4656. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4657. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4658. authorizeRetryTimes = 0;
  4659. return result;
  4660. }
  4661. else if(((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0))||
  4662. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4663. {
  4664. // Query from cache
  4665. DEBUG_INFO("Authorize from cache.\n");
  4666. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4667. // Query from list
  4668. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4669. {
  4670. DEBUG_INFO("Authorize from list.\n");
  4671. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4672. }
  4673. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4674. {
  4675. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4676. {
  4677. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4678. }
  4679. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4680. {
  4681. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4682. }
  4683. if(!GetOcppConnStatus())
  4684. {
  4685. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4686. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4687. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4688. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4689. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4690. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4691. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4692. authorizeRetryTimes = 0;
  4693. return result;
  4694. }
  4695. }
  4696. else
  4697. {
  4698. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4699. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4700. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4701. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4702. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4703. else
  4704. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4705. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4706. result = PASS;
  4707. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4708. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4709. authorizeRetryTimes = 0;
  4710. return result;
  4711. }
  4712. }
  4713. //initialize struct Authorize
  4714. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4715. //get data from shared memory
  4716. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4717. random_uuid(guid);
  4718. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4719. LWS_Send(message);
  4720. sprintf(tempdata, "Authorize,%d", gun_index);
  4721. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4722. {
  4723. result = PASS;
  4724. DEBUG_INFO("Authorize mapItem pass\n");
  4725. }
  4726. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4727. return result;
  4728. }
  4729. int sendBootNotificationRequest(void)
  4730. {
  4731. mtrace();
  4732. int result = FAIL;
  4733. char message[500]={0}, payload[700]={0};
  4734. char guid[37]={0};
  4735. char tempdata[65]={0};
  4736. // Fill BootNotification fields
  4737. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4738. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4739. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4740. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4741. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4742. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4743. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4744. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4745. ShmOCPP16DataPH->ChargeBoxId
  4746. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4747. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4748. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4749. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4750. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4751. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4752. random_uuid(guid);
  4753. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4754. LWS_Send(message);
  4755. sprintf(tempdata, "BootNotification,0");
  4756. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4757. {
  4758. result = PASS;
  4759. }
  4760. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4761. strcpy(queuedata,message);
  4762. return result;
  4763. }
  4764. int sendDataTransferRequest(int gun_index)
  4765. {
  4766. mtrace();
  4767. char message[1000]={0};
  4768. char guid[37]={0};
  4769. char tempdata[65]={0};
  4770. int result = FAIL;
  4771. random_uuid(guid);
  4772. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4773. MESSAGE_TYPE_CALL,
  4774. guid,
  4775. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4776. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4777. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4778. LWS_Send(message);
  4779. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4780. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4781. {
  4782. result = PASS;
  4783. DEBUG_INFO("DataTransfer mapItem pass\n");
  4784. }
  4785. return result;
  4786. }
  4787. int sendUnplugByDataTransferRequest(int gun_index)
  4788. {
  4789. mtrace();
  4790. char message[1000]={0};
  4791. char guid[37]={0};
  4792. char tempdata[65]={0};
  4793. int result = FAIL;
  4794. random_uuid(guid);
  4795. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4796. (gun_index+1),
  4797. MESSAGE_TYPE_CALL,
  4798. guid,
  4799. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4800. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4801. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4802. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4803. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4804. {
  4805. result = PASS;
  4806. DEBUG_INFO("DataTransfer mapItem pass\n");
  4807. }
  4808. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  4809. return result;
  4810. }
  4811. int sendDiagnosticsStatusNotificationRequest(char *status)
  4812. {
  4813. mtrace();
  4814. int result = FAIL;
  4815. char message[110]={0};
  4816. char guid[37]={0};
  4817. char tempdata[65]={0};
  4818. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4819. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4820. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4821. random_uuid(guid);
  4822. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4823. LWS_SendNow(message);
  4824. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4825. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4826. {
  4827. result = PASS;
  4828. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4829. }
  4830. //#ifdef SystemLogMessage
  4831. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4832. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4833. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4834. //#endif
  4835. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4836. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4837. //record status
  4838. if(strcmp(status,"Idle")==0)
  4839. {
  4840. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4841. }
  4842. else if(strcmp(status,"Uploaded")==0)
  4843. {
  4844. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4845. }
  4846. else if(strcmp(status,"UploadFailed")==0)
  4847. {
  4848. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4849. }
  4850. else if(strcmp(status,"Uploading")==0)
  4851. {
  4852. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4853. }
  4854. return result;
  4855. }
  4856. int sendFirmwareStatusNotificationRequest(char *status)
  4857. {
  4858. mtrace();
  4859. int result = FAIL;
  4860. char message[110]={0};
  4861. char guid[37]={0};
  4862. char tempdata[65]={0};
  4863. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4864. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4865. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4866. random_uuid(guid);
  4867. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4868. LWS_SendNow(message);
  4869. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4870. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4871. {
  4872. result = PASS;
  4873. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4874. }
  4875. //#ifdef SystemLogMessage
  4876. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4877. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4878. //#endif
  4879. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4880. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4881. //record status
  4882. if(strcmp(status,"Downloaded")==0)
  4883. {
  4884. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4885. }
  4886. else if(strcmp(status,"DownloadFailed")==0)
  4887. {
  4888. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4889. }
  4890. else if(strcmp(status,"Downloading")==0)
  4891. {
  4892. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4893. }
  4894. else if(strcmp(status,"Idle")==0)
  4895. {
  4896. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4897. }
  4898. else if(strcmp(status,"InstallationFailed")==0)
  4899. {
  4900. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4901. }
  4902. else if(strcmp(status,"Installing")==0)
  4903. {
  4904. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4905. }
  4906. else if(strcmp(status,"Installed")==0)
  4907. {
  4908. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4909. }
  4910. return result;
  4911. }
  4912. int sendHeartbeatRequest(int gun_index)
  4913. {
  4914. mtrace();
  4915. int result = FAIL;
  4916. char message[80]={0};
  4917. char guid[37]={0};
  4918. char tempdata[65]={0};
  4919. random_uuid(guid);
  4920. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4921. , MESSAGE_TYPE_CALL
  4922. , guid );
  4923. LWS_Send(message);
  4924. sprintf(tempdata, "Heartbeat,%d", 0);
  4925. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4926. {
  4927. result = PASS;
  4928. }
  4929. return result;
  4930. }
  4931. int sendStartTransactionRequest(int gun_index)
  4932. {
  4933. mtrace();
  4934. int result = FAIL;
  4935. char message[250]={0};
  4936. char guid[37]={0};
  4937. struct timeval tmnow;
  4938. struct tm *tm;
  4939. char buf[28];//, usec_buf[6];
  4940. char tempdata[65]={0};
  4941. int tempIndex = 0;
  4942. DEBUG_INFO("sendStartTransactionRequest...\n");
  4943. gettimeofday(&tmnow, NULL);
  4944. time_t t;
  4945. t = time(NULL);
  4946. /*UTC time and date*/
  4947. tm = gmtime(&t);
  4948. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4949. #if 0 // remove temporally
  4950. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4951. strcat(buf,".");
  4952. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4953. strcat(buf,usec_buf);
  4954. #endif
  4955. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4956. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4957. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4958. // clear StartTransaction Response
  4959. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4960. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4961. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4962. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4963. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4964. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4965. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4966. {
  4967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4968. {
  4969. tempIndex = ((gun_index==2) ? 1: 0);
  4970. }
  4971. else
  4972. {
  4973. tempIndex = gun_index;
  4974. }
  4975. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4976. {
  4977. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4978. {
  4979. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4980. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4981. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4982. }
  4983. }
  4984. }
  4985. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4986. {
  4987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4988. {
  4989. tempIndex = ((gun_index==2) ? 1: 0);
  4990. }
  4991. else
  4992. {
  4993. tempIndex = gun_index;
  4994. }
  4995. for (int index = 0; index < CCS_QUANTITY; index++)
  4996. {
  4997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4998. {
  4999. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5000. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5001. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5002. }
  5003. }
  5004. }
  5005. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5006. {
  5007. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5008. {
  5009. tempIndex = ((gun_index==2) ? 1: 0);
  5010. }
  5011. else
  5012. {
  5013. tempIndex = gun_index;
  5014. }
  5015. for (int index = 0; index < GB_QUANTITY; index++)
  5016. {
  5017. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5018. {
  5019. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5020. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5021. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5022. }
  5023. }
  5024. }
  5025. else if(gunType[gun_index] == GUN_TYPE_DO)
  5026. {
  5027. tempIndex = gun_index;
  5028. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5029. {
  5030. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5031. {
  5032. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5033. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5034. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5035. }
  5036. }
  5037. }
  5038. else
  5039. {
  5040. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5041. {
  5042. tempIndex = 2;
  5043. }
  5044. else
  5045. {
  5046. tempIndex = gun_index;
  5047. }
  5048. for (int index = 0; index < AC_QUANTITY; index++)
  5049. {
  5050. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5051. {
  5052. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5053. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5054. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5055. }
  5056. }
  5057. }
  5058. random_uuid(guid);
  5059. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5060. {
  5061. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5062. , gun_index +1
  5063. , MESSAGE_TYPE_CALL
  5064. , guid
  5065. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5066. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5067. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5068. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5069. }
  5070. else
  5071. {
  5072. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5073. , gun_index +1
  5074. , MESSAGE_TYPE_CALL
  5075. , guid
  5076. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5077. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5078. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5079. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  5080. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5081. }
  5082. #if 1
  5083. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5084. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5085. {
  5086. result = PASS;
  5087. }
  5088. #endif
  5089. strcpy(queuedata, message);
  5090. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5091. OCPP_insert_transaction_msg(YES, queuedata);
  5092. return result;
  5093. }
  5094. int sendStatusNotificationRequest(int gun_index)
  5095. {
  5096. mtrace();
  5097. int result = FAIL;
  5098. char message[600]={0};
  5099. char guid[37];
  5100. int currentStatus = 0;
  5101. struct timeval tmnow;
  5102. struct tm *tm;
  5103. char buf[28];//, usec_buf[6];
  5104. char tempdata[65]={0};
  5105. int tempIndex = 0;
  5106. uint8_t isStateChanged = TRUE;
  5107. uint8_t isContentIllegal = TRUE;
  5108. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5109. gettimeofday(&tmnow, NULL);
  5110. time_t t;
  5111. t = time(NULL);
  5112. /*UTC time and date*/
  5113. tm = gmtime(&t);
  5114. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5115. #if 0 // remove temporally
  5116. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5117. strcat(buf,".");
  5118. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5119. strcat(buf,usec_buf);
  5120. #endif
  5121. //printf("%s",buf);
  5122. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5123. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5124. // it's option
  5125. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5126. /*
  5127. enum _SYSTEM_STATUS
  5128. {
  5129. S_BOOTING = 0,
  5130. S_IDLE, = 1
  5131. S_AUTHORIZING, =2
  5132. S_REASSIGN_CHECK, =3
  5133. S_REASSIGN, =4
  5134. S_PRECHARGE, =5
  5135. S_PREPARING_FOR_EV, =6
  5136. S_PREPARING_FOR_EVSE, =7
  5137. S_CHARGING, =8
  5138. S_TERMINATING, =9
  5139. S_COMPLETE, =10
  5140. S_ALARM, =11
  5141. S_FAULT =12
  5142. }
  5143. */
  5144. //check Transaction active
  5145. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5146. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5147. {
  5148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5149. {
  5150. tempIndex = ((gun_index==2) ? 1: 0);
  5151. }
  5152. else
  5153. {
  5154. tempIndex = gun_index;
  5155. }
  5156. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5157. {
  5158. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5159. {
  5160. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5161. {
  5162. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5163. {
  5164. currentStatus = Preparing; //OCPP Status: Preparing
  5165. }
  5166. else
  5167. {
  5168. currentStatus = Available; //OCPP Status: Available
  5169. }
  5170. }
  5171. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5172. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5173. ) //S_PRECHARGE
  5174. {
  5175. currentStatus = Preparing; //OCPP Status: Preparing
  5176. }
  5177. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5178. {
  5179. currentStatus = Charging; //OCPP Status: Charging
  5180. }
  5181. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5182. {
  5183. currentStatus = Finishing; //OCPP Status: Finishing
  5184. }
  5185. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5186. {
  5187. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5188. }
  5189. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5190. {
  5191. currentStatus = Unavailable; //OCPP Status: Unavailable
  5192. }
  5193. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5194. {
  5195. currentStatus = Faulted; //OCPP Status: Faulted
  5196. }
  5197. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5198. {
  5199. currentStatus = Reserved; //OCPP Status: Reserved
  5200. }
  5201. } //end of the same index
  5202. }//end of for CHAdeMO_QUANTITY
  5203. }
  5204. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5205. {
  5206. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5207. {
  5208. tempIndex = ((gun_index==2) ? 1: 0);
  5209. }
  5210. else
  5211. {
  5212. tempIndex = gun_index;
  5213. }
  5214. for (int index = 0; index < CCS_QUANTITY; index++)
  5215. {
  5216. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5217. {
  5218. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5219. {
  5220. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5221. {
  5222. currentStatus = Preparing; //OCPP Status: Preparing
  5223. }
  5224. else
  5225. {
  5226. currentStatus = Available; //OCPP Status: Available
  5227. }
  5228. }
  5229. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5230. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5231. ) //S_PRECHARGE
  5232. {
  5233. currentStatus = Preparing; //OCPP Status: Preparing
  5234. }
  5235. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5236. {
  5237. currentStatus = Charging; //OCPP Status: Charging
  5238. }
  5239. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5240. {
  5241. currentStatus = Finishing; //OCPP Status: Finishing
  5242. }
  5243. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5244. {
  5245. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5246. }
  5247. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5248. {
  5249. currentStatus = Unavailable; //OCPP Status : Unavailable
  5250. }
  5251. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5252. {
  5253. currentStatus = Faulted; //OCPP Status: Faulted
  5254. }
  5255. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5256. {
  5257. currentStatus = Reserved; //OCPP Status: Reserved
  5258. }
  5259. } //end of the same index
  5260. } // end of for CCS_QUANTITY
  5261. }
  5262. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5263. {
  5264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5265. {
  5266. tempIndex = ((gun_index==2) ? 1: 0);
  5267. }
  5268. else
  5269. {
  5270. tempIndex = gun_index;
  5271. }
  5272. for (int index = 0; index < GB_QUANTITY; index++)
  5273. {
  5274. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5275. {
  5276. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5277. {
  5278. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5279. {
  5280. currentStatus = Preparing; //OCPP Status: Preparing
  5281. }
  5282. else
  5283. {
  5284. currentStatus = Available; //OCPP Status: Available
  5285. }
  5286. }
  5287. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5288. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5289. ) //S_PRECHARGE
  5290. {
  5291. currentStatus = Preparing; //OCPP Status: Preparing
  5292. }
  5293. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5294. {
  5295. currentStatus = Charging; //OCPP Status: Charging
  5296. }
  5297. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5298. {
  5299. currentStatus = Finishing; //OCPP Status: Finishing
  5300. }
  5301. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5302. {
  5303. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5304. }
  5305. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5306. {
  5307. currentStatus = Unavailable; //OCPP Status: Unavailable
  5308. }
  5309. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5310. {
  5311. currentStatus = Faulted; //OCPP Status: Faulted
  5312. }
  5313. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5314. {
  5315. currentStatus = Reserved; //OCPP Status: Reserved
  5316. }
  5317. } //end of the same index
  5318. } // end of for GB_QUANTITY
  5319. }
  5320. else if(gunType[gun_index] == GUN_TYPE_DO)
  5321. {
  5322. tempIndex = gun_index;
  5323. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5324. {
  5325. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5326. {
  5327. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5328. {
  5329. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5330. {
  5331. currentStatus = Preparing; //OCPP Status: Preparing
  5332. }
  5333. else
  5334. {
  5335. currentStatus = Available; //OCPP Status: Available
  5336. }
  5337. }
  5338. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5339. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5340. ) //S_PRECHARGE
  5341. {
  5342. currentStatus = Preparing; //OCPP Status: Preparing
  5343. }
  5344. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5345. {
  5346. currentStatus = Charging; //OCPP Status: Charging
  5347. }
  5348. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5349. {
  5350. currentStatus = Finishing; //OCPP Status: Finishing
  5351. }
  5352. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5353. {
  5354. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5355. }
  5356. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5357. {
  5358. currentStatus = Unavailable; //OCPP Status: Unavailable
  5359. }
  5360. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5361. {
  5362. currentStatus = Faulted; //OCPP Status: Faulted
  5363. }
  5364. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5365. {
  5366. currentStatus = Reserved; //OCPP Status: Reserved
  5367. }
  5368. } //end of the same index
  5369. }
  5370. }
  5371. else
  5372. {
  5373. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5374. {
  5375. tempIndex = 2;
  5376. }
  5377. else
  5378. {
  5379. tempIndex = gun_index;
  5380. }
  5381. for (int index = 0; index < AC_QUANTITY; index++)
  5382. {
  5383. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5384. {
  5385. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5386. {
  5387. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  5388. {
  5389. currentStatus = Preparing; //OCPP Status: Preparing
  5390. }
  5391. else
  5392. {
  5393. currentStatus = Available; //OCPP Status: Available
  5394. }
  5395. }
  5396. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5397. {
  5398. currentStatus = Preparing; //OCPP Status: Preparing
  5399. }
  5400. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5401. {
  5402. currentStatus = Charging; //OCPP Status: Charging
  5403. }
  5404. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5405. {
  5406. currentStatus = Finishing; //OCPP Status: Finishing
  5407. }
  5408. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5409. {
  5410. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5411. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5412. else
  5413. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5414. }
  5415. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5416. {
  5417. currentStatus = Unavailable; //OCPP Status: Unavailable
  5418. }
  5419. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5420. {
  5421. currentStatus = Faulted; //OCPP Status: Faulted
  5422. }
  5423. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5424. {
  5425. currentStatus = Reserved; //OCPP Status: Reserved
  5426. }
  5427. }//end of the same index
  5428. }//end of for AC_QUANTITY
  5429. }
  5430. //it's option
  5431. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5432. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5433. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5434. {
  5435. isStateChanged = FALSE;
  5436. }
  5437. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5438. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5439. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5440. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5441. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5442. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5443. isContentIllegal = TRUE;
  5444. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5445. {
  5446. if(strcmp((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5447. {
  5448. isContentIllegal = FALSE;
  5449. break;
  5450. }
  5451. }
  5452. if(isContentIllegal)
  5453. {
  5454. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5455. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5456. }
  5457. random_uuid(guid);
  5458. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5459. , MESSAGE_TYPE_CALL
  5460. , guid
  5461. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5462. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5463. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5464. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5465. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5466. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5467. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5468. if((server_sign == TRUE) && isStateChanged)
  5469. {
  5470. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5471. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5472. LWS_Send(message);
  5473. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5474. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5475. {
  5476. //DEBUG_ERROR("statusNotification mapitem pass");
  5477. result = PASS;
  5478. }
  5479. }
  5480. else
  5481. {
  5482. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5483. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5484. result = PASS;
  5485. }
  5486. return result;
  5487. }
  5488. int sendStopTransactionRequest(int gun_index)
  5489. {
  5490. mtrace();
  5491. int result = FAIL;
  5492. //char message[1500]={0};
  5493. char guid[37]={0};
  5494. char tempdata[65]={0};
  5495. int tempIndex = 0;
  5496. char TempStopTransaction[256];
  5497. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5498. //int idx_sample=0;
  5499. DEBUG_INFO("sendStopTransactionRequest \n");
  5500. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5501. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5502. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5503. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5504. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5505. {
  5506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5507. {
  5508. tempIndex = ((gun_index==2) ? 1: 0);
  5509. }
  5510. else
  5511. {
  5512. tempIndex = gun_index;
  5513. }
  5514. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5515. {
  5516. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5517. {
  5518. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5519. }
  5520. }// END OF CHAdeMO_QUANTITY
  5521. }
  5522. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5523. {
  5524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5525. {
  5526. tempIndex = ((gun_index==2) ? 1: 0);
  5527. }
  5528. else
  5529. {
  5530. tempIndex = gun_index;
  5531. }
  5532. for (int index = 0; index < CCS_QUANTITY; index++)
  5533. {
  5534. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5535. {
  5536. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5537. }
  5538. }// END OF CCS_QUANTITY
  5539. }
  5540. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5541. {
  5542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5543. {
  5544. tempIndex = ((gun_index==2) ? 1: 0);
  5545. }
  5546. else
  5547. {
  5548. tempIndex = gun_index;
  5549. }
  5550. for (int index = 0; index < GB_QUANTITY; index++)
  5551. {
  5552. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5553. {
  5554. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5555. }
  5556. }// END OF GB_QUANTITY
  5557. }
  5558. else if(gunType[gun_index] == GUN_TYPE_DO)
  5559. {
  5560. tempIndex = gun_index;
  5561. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5562. {
  5563. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5564. {
  5565. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5566. }
  5567. }// END OF GB_QUANTITY
  5568. }
  5569. else
  5570. {
  5571. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5572. {
  5573. tempIndex = 2;
  5574. }
  5575. else
  5576. {
  5577. tempIndex = gun_index;
  5578. }
  5579. for (int index = 0; index < AC_QUANTITY; index++)
  5580. {
  5581. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5582. {
  5583. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5584. }
  5585. }// END OF AC_QUANTITY
  5586. }
  5587. //====================================== Stop Transaction Time =====================================================
  5588. struct timeval tmnow;
  5589. struct tm *tm;
  5590. char buf[28];//, usec_buf[6];
  5591. gettimeofday(&tmnow, NULL);
  5592. time_t t;
  5593. t = time(NULL);
  5594. /*UTC time and date*/
  5595. tm = gmtime(&t);
  5596. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5598. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5599. random_uuid(guid);
  5600. /***********************************transactionData******************************************************/
  5601. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5602. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5603. //=================================
  5604. // Transaction_Begin
  5605. //=================================
  5606. //=================================
  5607. // Transaction_End
  5608. //=================================
  5609. // ================================= Current.Import L1 ===============================================
  5610. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5611. {
  5612. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5613. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5614. {
  5615. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5616. {
  5617. tempIndex = ((gun_index==2) ? 1: 0);
  5618. }
  5619. else
  5620. {
  5621. tempIndex = gun_index;
  5622. }
  5623. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5624. {
  5625. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5626. {
  5627. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5628. }
  5629. }// End of for CHAdeMO_QUANTITY
  5630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5631. }
  5632. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5633. {
  5634. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5635. {
  5636. tempIndex = ((gun_index==2) ? 1: 0);
  5637. }
  5638. else
  5639. {
  5640. tempIndex = gun_index;
  5641. }
  5642. for (int index = 0; index < CCS_QUANTITY; index++)
  5643. {
  5644. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5645. {
  5646. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5647. }
  5648. }// End of for CCS_QUANTITY
  5649. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5650. }
  5651. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5652. {
  5653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5654. {
  5655. tempIndex = ((gun_index==2) ? 1: 0);
  5656. }
  5657. else
  5658. {
  5659. tempIndex = gun_index;
  5660. }
  5661. for (int index = 0; index < GB_QUANTITY; index++)
  5662. {
  5663. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5664. {
  5665. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5666. }
  5667. }// End of for GB_QUANTITY
  5668. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5669. }
  5670. else if(gunType[gun_index] == GUN_TYPE_DO)
  5671. {
  5672. tempIndex = gun_index;
  5673. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5674. {
  5675. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5676. {
  5677. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5678. }
  5679. }
  5680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5681. }
  5682. else
  5683. {
  5684. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5685. {
  5686. tempIndex = 2;
  5687. }
  5688. else
  5689. {
  5690. tempIndex = gun_index;
  5691. }
  5692. for (int index = 0; index < AC_QUANTITY; index++)
  5693. {
  5694. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5695. {
  5696. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5697. }
  5698. }// End of for AC_QUANTITY
  5699. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5700. }
  5701. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5702. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5703. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5704. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5705. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5706. }
  5707. // ================================= Energy.Active.Import.Interval ==============================================
  5708. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5709. {
  5710. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5711. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5712. {
  5713. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5714. {
  5715. tempIndex = ((gun_index==2) ? 1: 0);
  5716. }
  5717. else
  5718. {
  5719. tempIndex = gun_index;
  5720. }
  5721. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5722. {
  5723. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5724. {
  5725. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5726. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5727. }
  5728. }// END OF CHAdeMO_QUANTITY
  5729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5730. }
  5731. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5732. {
  5733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5734. {
  5735. tempIndex = ((gun_index==2) ? 1: 0);
  5736. }
  5737. else
  5738. {
  5739. tempIndex = gun_index;
  5740. }
  5741. for (int index = 0; index < CCS_QUANTITY; index++)
  5742. {
  5743. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5744. {
  5745. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5746. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5747. }
  5748. }// END OF CCS_QUANTITY
  5749. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5750. }
  5751. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5752. {
  5753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5754. {
  5755. tempIndex = ((gun_index==2) ? 1: 0);
  5756. }
  5757. else
  5758. {
  5759. tempIndex = gun_index;
  5760. }
  5761. for (int index = 0; index < GB_QUANTITY; index++)
  5762. {
  5763. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5764. {
  5765. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5766. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5767. }
  5768. }// END OF GB_QUANTITY
  5769. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5770. }
  5771. else if(gunType[gun_index] == GUN_TYPE_DO)
  5772. {
  5773. tempIndex = gun_index;
  5774. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5775. {
  5776. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5777. {
  5778. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5779. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5780. }
  5781. }
  5782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5783. }
  5784. else
  5785. {
  5786. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5787. {
  5788. tempIndex = 2;
  5789. }
  5790. else
  5791. {
  5792. tempIndex = gun_index;
  5793. }
  5794. for (int index = 0; index < AC_QUANTITY; index++)
  5795. {
  5796. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5797. {
  5798. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5799. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5800. }
  5801. }// END OF AC_QUANTITY
  5802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5803. }
  5804. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5806. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5809. }
  5810. //=================================== Power.Active.Import ==================================================
  5811. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5812. {
  5813. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5814. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5815. {
  5816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5817. {
  5818. tempIndex = ((gun_index==2) ? 1: 0);
  5819. }
  5820. else
  5821. {
  5822. tempIndex = gun_index;
  5823. }
  5824. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5825. {
  5826. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5827. {
  5828. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5829. }
  5830. } // End for CHAdeMO_QUANTITY
  5831. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5832. }
  5833. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5834. {
  5835. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5836. {
  5837. tempIndex = ((gun_index==2) ? 1: 0);
  5838. }
  5839. else
  5840. {
  5841. tempIndex = gun_index;
  5842. }
  5843. for (int index = 0; index < CCS_QUANTITY; index++)
  5844. {
  5845. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5846. {
  5847. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5848. }
  5849. } // END for CCS_QUANTITY
  5850. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5851. }
  5852. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5853. {
  5854. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5855. {
  5856. tempIndex = ((gun_index==2) ? 1: 0);
  5857. }
  5858. else
  5859. {
  5860. tempIndex = gun_index;
  5861. }
  5862. for (int index = 0; index < GB_QUANTITY; index++)
  5863. {
  5864. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5865. {
  5866. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5867. }
  5868. }// END for GB_QUANTITY
  5869. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5870. }
  5871. else if(gunType[gun_index] == GUN_TYPE_DO)
  5872. {
  5873. tempIndex = gun_index;
  5874. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5875. {
  5876. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5877. {
  5878. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5879. }
  5880. }
  5881. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5882. }
  5883. else
  5884. {
  5885. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5886. {
  5887. tempIndex = 2;
  5888. }
  5889. else
  5890. {
  5891. tempIndex = gun_index;
  5892. }
  5893. for (int index = 0; index < AC_QUANTITY; index++)
  5894. {
  5895. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5896. {
  5897. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5898. }
  5899. } // END for AC_QUANTITY
  5900. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5901. }
  5902. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5903. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5904. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5905. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5906. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5907. }
  5908. //============================ Voltage L1 ====================================
  5909. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5910. {
  5911. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5912. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5913. {
  5914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5915. {
  5916. tempIndex = ((gun_index==2) ? 1: 0);
  5917. }
  5918. else
  5919. {
  5920. tempIndex = gun_index;
  5921. }
  5922. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5923. {
  5924. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5925. {
  5926. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5927. }
  5928. } // END OF FOR CHAdeMO_QUANTITY
  5929. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5930. }
  5931. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5932. {
  5933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5934. {
  5935. tempIndex = ((gun_index==2) ? 1: 0);
  5936. }
  5937. else
  5938. {
  5939. tempIndex = gun_index;
  5940. }
  5941. for (int index = 0; index < CCS_QUANTITY; index++)
  5942. {
  5943. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5944. {
  5945. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5946. }
  5947. } // END OF FOR CCS_QUANTITY
  5948. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5949. }
  5950. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5951. {
  5952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5953. {
  5954. tempIndex = ((gun_index==2) ? 1: 0);
  5955. }
  5956. else
  5957. {
  5958. tempIndex = gun_index;
  5959. }
  5960. for (int index = 0; index < GB_QUANTITY; index++)
  5961. {
  5962. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5963. {
  5964. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5965. }
  5966. } // END OF FOR GB_QUANTITY
  5967. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5968. }
  5969. else if(gunType[gun_index] == GUN_TYPE_DO)
  5970. {
  5971. tempIndex = gun_index;
  5972. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5973. {
  5974. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5975. {
  5976. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5977. }
  5978. }
  5979. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5980. }
  5981. else
  5982. {
  5983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5984. {
  5985. tempIndex = 2;
  5986. }
  5987. else
  5988. {
  5989. tempIndex = gun_index;
  5990. }
  5991. for (int index = 0; index < AC_QUANTITY; index++)
  5992. {
  5993. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5994. {
  5995. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5996. }
  5997. } // END OF FOR AC_QUANTITY
  5998. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5999. }
  6000. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6002. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6003. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6004. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6005. }
  6006. //====================== End SoC ================================
  6007. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6008. {
  6009. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6010. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6011. {
  6012. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6013. {
  6014. tempIndex = ((gun_index==2) ? 1: 0);
  6015. }
  6016. else
  6017. {
  6018. tempIndex = gun_index;
  6019. }
  6020. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6021. {
  6022. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6023. {
  6024. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6025. {
  6026. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6027. }
  6028. }
  6029. }
  6030. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6031. {
  6032. for (int index = 0; index < CCS_QUANTITY; index++)
  6033. {
  6034. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6035. {
  6036. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6037. }
  6038. }
  6039. }
  6040. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6041. {
  6042. for (int index = 0; index < GB_QUANTITY; index++)
  6043. {
  6044. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6045. {
  6046. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6047. }
  6048. }
  6049. }
  6050. else if(gunType[gun_index] == GUN_TYPE_DO)
  6051. {
  6052. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6053. {
  6054. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6055. {
  6056. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6057. }
  6058. }
  6059. }
  6060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6061. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6062. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6063. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6064. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6065. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6066. } // END FOR DC CASE
  6067. }
  6068. // ================================= Current.Import L2 ===============================================
  6069. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6070. {
  6071. // AC 3 phse L2 current
  6072. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6073. {
  6074. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6075. {
  6076. tempIndex = 2;
  6077. }
  6078. else
  6079. {
  6080. tempIndex = gun_index;
  6081. }
  6082. for (int index = 0; index < AC_QUANTITY; index++)
  6083. {
  6084. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6085. {
  6086. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6087. }
  6088. }// End of for AC_QUANTITY
  6089. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6090. }
  6091. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6092. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6093. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6094. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6095. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6096. }
  6097. // ================================= Current.Import L3 ===============================================
  6098. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6099. {
  6100. // AC 3 phse L3 current
  6101. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6102. {
  6103. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6104. {
  6105. tempIndex = 2;
  6106. }
  6107. else
  6108. {
  6109. tempIndex = gun_index;
  6110. }
  6111. for (int index = 0; index < AC_QUANTITY; index++)
  6112. {
  6113. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6114. {
  6115. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6116. }
  6117. }// End of for AC_QUANTITY
  6118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6119. }
  6120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6121. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6122. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6123. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6124. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6125. }
  6126. //============================ Voltage L2 ====================================
  6127. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6128. {
  6129. // AC 3 phse L2 voltage
  6130. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6131. {
  6132. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6133. {
  6134. tempIndex = 2;
  6135. }
  6136. else
  6137. {
  6138. tempIndex = gun_index;
  6139. }
  6140. for (int index = 0; index < AC_QUANTITY; index++)
  6141. {
  6142. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6143. {
  6144. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6145. }
  6146. } // END OF FOR AC_QUANTITY
  6147. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6148. }
  6149. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6150. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6151. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6152. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6153. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6154. }
  6155. //============================ Voltage L3 ====================================
  6156. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6157. {
  6158. // AC 3 phse L3 voltage
  6159. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6160. {
  6161. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6162. {
  6163. tempIndex = 2;
  6164. }
  6165. else
  6166. {
  6167. tempIndex = gun_index;
  6168. }
  6169. for (int index = 0; index < AC_QUANTITY; index++)
  6170. {
  6171. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6172. {
  6173. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6174. }
  6175. } // END OF FOR AC_QUANTITY
  6176. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6177. }
  6178. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6179. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6180. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6181. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6182. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6183. }
  6184. //====================== Start SoC ================================
  6185. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6186. {
  6187. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6188. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6189. {
  6190. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6191. {
  6192. tempIndex = ((gun_index==2) ? 1: 0);
  6193. }
  6194. else
  6195. {
  6196. tempIndex = gun_index;
  6197. }
  6198. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6199. {
  6200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6201. {
  6202. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6203. {
  6204. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6205. }
  6206. }
  6207. }
  6208. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6209. {
  6210. for (int index = 0; index < CCS_QUANTITY; index++)
  6211. {
  6212. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6213. {
  6214. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6215. }
  6216. }
  6217. }
  6218. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6219. {
  6220. for (int index = 0; index < GB_QUANTITY; index++)
  6221. {
  6222. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6223. {
  6224. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6225. }
  6226. }
  6227. }
  6228. else if(gunType[gun_index] == GUN_TYPE_DO)
  6229. {
  6230. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6231. {
  6232. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6233. {
  6234. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6235. }
  6236. }
  6237. }
  6238. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6239. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6240. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6241. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6242. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6243. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6244. } // END FOR DC CASE
  6245. }
  6246. //================================================ Message create ====================================================
  6247. json_object *StopTransaction = json_object_new_object();
  6248. json_object *transactionDatas = json_object_new_array();
  6249. json_object *sampledValues = json_object_new_array();
  6250. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6251. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6252. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6253. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6254. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6255. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6256. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6257. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6258. {
  6259. json_object *transactionData = json_object_new_object();
  6260. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6261. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6262. {
  6263. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6264. {
  6265. json_object *sampledValue = json_object_new_object();
  6266. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6267. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6268. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6269. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6270. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6271. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6272. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6273. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6274. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6275. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6276. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6277. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6278. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6279. json_object_array_add(sampledValues, sampledValue);
  6280. }
  6281. }
  6282. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6283. json_object_array_add(transactionDatas, transactionData);
  6284. }
  6285. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6286. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6287. ,MESSAGE_TYPE_CALL
  6288. ,guid
  6289. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6290. json_object_put(StopTransaction);
  6291. #if 1 // for TempStopTransaction
  6292. //Delete TempStopTransaction
  6293. if((access(TempStopTransaction,F_OK))!=-1)
  6294. {
  6295. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6296. }
  6297. #endif
  6298. #if 1
  6299. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6300. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6301. {
  6302. result = PASS;
  6303. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6304. }
  6305. #endif
  6306. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6307. OCPP_insert_transaction_msg(NO, queuedata);
  6308. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6309. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6310. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6311. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6312. {
  6313. //SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6314. }
  6315. //for test
  6316. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6317. return result;
  6318. }
  6319. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6320. {
  6321. mtrace();
  6322. int result = FAIL;
  6323. char guid[37]={0};
  6324. char tempdata[65]={0};
  6325. int tempIndex = 0;
  6326. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6327. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6328. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6329. //set value
  6330. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6331. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6332. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6333. -1);
  6334. random_uuid(guid);
  6335. //UTC Date time
  6336. struct timeval tmnow;
  6337. struct tm *tm;
  6338. char buf[28];//, usec_buf[6];
  6339. gettimeofday(&tmnow, NULL);
  6340. time_t t;
  6341. t = time(NULL);
  6342. /*UTC time and date*/
  6343. tm = gmtime(&t);
  6344. if(dataType == ReadingContext_Sample_Clock)
  6345. {
  6346. struct tm *tmTarget;
  6347. struct timeb tbTarget;
  6348. tbTarget.time = mktime(tm);
  6349. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6350. tmTarget = gmtime(&tbTarget.time);
  6351. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6352. }
  6353. else
  6354. {
  6355. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6356. }
  6357. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6358. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6359. //********************************(1)Current.Import L1************************************************/
  6360. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6361. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6362. (dataType == ReadingContext_Trigger))
  6363. {
  6364. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6365. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6366. {
  6367. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6368. {
  6369. tempIndex = ((gun_index==2) ? 1: 0);
  6370. }
  6371. else
  6372. {
  6373. tempIndex = gun_index;
  6374. }
  6375. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6376. {
  6377. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6378. {
  6379. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6380. }
  6381. }
  6382. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6383. }
  6384. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6385. {
  6386. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6387. {
  6388. tempIndex = ((gun_index==2) ? 1: 0);
  6389. }
  6390. else
  6391. {
  6392. tempIndex = gun_index;
  6393. }
  6394. for (int index = 0; index < CCS_QUANTITY; index++)
  6395. {
  6396. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6397. {
  6398. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6399. }
  6400. }
  6401. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6402. }
  6403. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6404. {
  6405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6406. {
  6407. tempIndex = ((gun_index==2) ? 1: 0);
  6408. }
  6409. else
  6410. {
  6411. tempIndex = gun_index;
  6412. }
  6413. for (int index = 0; index < GB_QUANTITY; index++)
  6414. {
  6415. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6416. {
  6417. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6418. }
  6419. }
  6420. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6421. }
  6422. else if(gunType[gun_index] == GUN_TYPE_DO)
  6423. {
  6424. tempIndex = gun_index;
  6425. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6426. {
  6427. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6428. {
  6429. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6430. }
  6431. }
  6432. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6433. }
  6434. else
  6435. {
  6436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6437. {
  6438. tempIndex = 2;
  6439. }
  6440. else
  6441. {
  6442. tempIndex = gun_index;
  6443. }
  6444. for (int index = 0; index < AC_QUANTITY; index++)
  6445. {
  6446. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6447. {
  6448. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6449. }
  6450. }
  6451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6452. }
  6453. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6454. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6455. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6456. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6457. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6458. }
  6459. //********************************(2)Energy.Active.Import.Register ************************************************/
  6460. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6461. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6462. (dataType == ReadingContext_Trigger))
  6463. {
  6464. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6465. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6466. {
  6467. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6468. {
  6469. tempIndex = ((gun_index==2) ? 1: 0);
  6470. }
  6471. else
  6472. {
  6473. tempIndex = gun_index;
  6474. }
  6475. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6476. {
  6477. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6478. {
  6479. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6480. }
  6481. }
  6482. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6483. }
  6484. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6485. {
  6486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6487. {
  6488. tempIndex = ((gun_index==2) ? 1: 0);
  6489. }
  6490. else
  6491. {
  6492. tempIndex = gun_index;
  6493. }
  6494. for (int index = 0; index < CCS_QUANTITY; index++)
  6495. {
  6496. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6497. {
  6498. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6499. }
  6500. }
  6501. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6502. }
  6503. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6504. {
  6505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6506. {
  6507. tempIndex = ((gun_index==2) ? 1: 0);
  6508. }
  6509. else
  6510. {
  6511. tempIndex = gun_index;
  6512. }
  6513. for (int index = 0; index < GB_QUANTITY; index++)
  6514. {
  6515. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6516. {
  6517. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6518. }
  6519. }
  6520. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6521. }
  6522. else if(gunType[gun_index] == GUN_TYPE_DO)
  6523. {
  6524. tempIndex = gun_index;
  6525. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6526. {
  6527. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6528. {
  6529. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6530. }
  6531. }
  6532. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6533. }
  6534. else
  6535. {
  6536. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6537. {
  6538. tempIndex = 2;
  6539. }
  6540. else
  6541. {
  6542. tempIndex = gun_index;
  6543. }
  6544. for (int index = 0; index < AC_QUANTITY; index++)
  6545. {
  6546. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6547. {
  6548. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6549. }
  6550. }
  6551. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6552. }
  6553. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6554. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6555. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6556. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6557. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6558. }
  6559. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6560. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6561. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6562. (dataType == ReadingContext_Trigger))
  6563. {
  6564. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6565. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6566. {
  6567. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6568. {
  6569. tempIndex = ((gun_index==2) ? 1: 0);
  6570. }
  6571. else
  6572. {
  6573. tempIndex = gun_index;
  6574. }
  6575. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6576. {
  6577. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6578. {
  6579. if(dataType == ReadingContext_Sample_Clock)
  6580. {
  6581. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6582. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6583. }
  6584. else if(dataType == ReadingContext_Sample_Periodic)
  6585. {
  6586. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6587. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6588. }
  6589. else
  6590. {
  6591. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6592. }
  6593. }
  6594. } // END OF FOR CHAdeMO_QUANTITY
  6595. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6596. }
  6597. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6598. {
  6599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6600. {
  6601. tempIndex = ((gun_index==2) ? 1: 0);
  6602. }
  6603. else
  6604. {
  6605. tempIndex = gun_index;
  6606. }
  6607. for (int index = 0; index < CCS_QUANTITY; index++)
  6608. {
  6609. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6610. {
  6611. if(dataType == ReadingContext_Sample_Clock)
  6612. {
  6613. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6614. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6615. }
  6616. else if(dataType == ReadingContext_Sample_Periodic)
  6617. {
  6618. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6619. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6620. }
  6621. else
  6622. {
  6623. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6624. }
  6625. }
  6626. } // END OF CCS_QUANTITY
  6627. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6628. }
  6629. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6630. {
  6631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6632. {
  6633. tempIndex = ((gun_index==2) ? 1: 0);
  6634. }
  6635. else
  6636. {
  6637. tempIndex = gun_index;
  6638. }
  6639. for (int index = 0; index < GB_QUANTITY; index++)
  6640. {
  6641. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6642. {
  6643. if(dataType == ReadingContext_Sample_Clock)
  6644. {
  6645. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6646. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6647. }
  6648. else if(dataType == ReadingContext_Sample_Periodic)
  6649. {
  6650. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6651. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6652. }
  6653. else
  6654. {
  6655. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6656. }
  6657. }
  6658. } // END OF GB_QUANTITY
  6659. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6660. }
  6661. else if(gunType[gun_index] == GUN_TYPE_DO)
  6662. {
  6663. tempIndex = gun_index;
  6664. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6665. {
  6666. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6667. {
  6668. if(dataType == ReadingContext_Sample_Clock)
  6669. {
  6670. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  6671. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6672. }
  6673. else if(dataType == ReadingContext_Sample_Periodic)
  6674. {
  6675. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6676. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6677. }
  6678. else
  6679. {
  6680. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6681. }
  6682. }
  6683. }
  6684. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6685. }
  6686. else
  6687. {
  6688. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6689. {
  6690. tempIndex = 2;
  6691. }
  6692. else
  6693. {
  6694. tempIndex = gun_index;
  6695. }
  6696. for (int index = 0; index < AC_QUANTITY; index++)
  6697. {
  6698. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6699. {
  6700. if(dataType == ReadingContext_Sample_Clock)
  6701. {
  6702. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6703. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6704. }
  6705. else if(dataType == ReadingContext_Sample_Periodic)
  6706. {
  6707. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6708. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6709. }
  6710. else
  6711. {
  6712. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6713. }
  6714. }
  6715. }
  6716. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6717. }
  6718. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6719. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6720. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6721. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6722. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6723. }
  6724. //********************************(4)Power.Active.Import************************************************/
  6725. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6726. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6727. (dataType == ReadingContext_Trigger))
  6728. {
  6729. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6730. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6731. {
  6732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6733. {
  6734. tempIndex = ((gun_index==2) ? 1: 0);
  6735. }
  6736. else
  6737. {
  6738. tempIndex = gun_index;
  6739. }
  6740. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6741. {
  6742. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6743. {
  6744. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6745. }
  6746. } // END OF FOR
  6747. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6748. }
  6749. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6750. {
  6751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6752. {
  6753. tempIndex = ((gun_index==2) ? 1: 0);
  6754. }
  6755. else
  6756. {
  6757. tempIndex = gun_index;
  6758. }
  6759. for (int index = 0; index < CCS_QUANTITY; index++)
  6760. {
  6761. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6762. {
  6763. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6764. }
  6765. }
  6766. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6767. }
  6768. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6769. {
  6770. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6771. {
  6772. tempIndex = ((gun_index==2) ? 1: 0);
  6773. }
  6774. else
  6775. {
  6776. tempIndex = gun_index;
  6777. }
  6778. for (int index = 0; index < GB_QUANTITY; index++)
  6779. {
  6780. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6781. {
  6782. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6783. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6784. }
  6785. }
  6786. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6787. }
  6788. else if(gunType[gun_index] == GUN_TYPE_DO)
  6789. {
  6790. tempIndex = gun_index;
  6791. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6792. {
  6793. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6794. {
  6795. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6796. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6797. }
  6798. }
  6799. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6800. }
  6801. else
  6802. {
  6803. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6804. {
  6805. tempIndex = 2;
  6806. }
  6807. else
  6808. {
  6809. tempIndex = gun_index;
  6810. }
  6811. for (int index = 0; index < AC_QUANTITY; index++)
  6812. {
  6813. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6814. {
  6815. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6816. }
  6817. }
  6818. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6819. }
  6820. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6821. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6822. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6823. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6824. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6825. }
  6826. //***********************************************(5)VOLTAGE L1******************************************************/
  6827. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6828. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6829. (dataType == ReadingContext_Trigger))
  6830. {
  6831. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6832. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6833. {
  6834. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6835. {
  6836. tempIndex = ((gun_index==2) ? 1: 0);
  6837. }
  6838. else
  6839. {
  6840. tempIndex = gun_index;
  6841. }
  6842. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6843. {
  6844. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6845. {
  6846. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6847. }
  6848. }
  6849. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6850. }
  6851. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6852. {
  6853. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6854. {
  6855. tempIndex = ((gun_index==2) ? 1: 0);
  6856. }
  6857. else
  6858. {
  6859. tempIndex = gun_index;
  6860. }
  6861. for (int index = 0; index < CCS_QUANTITY; index++)
  6862. {
  6863. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6864. {
  6865. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6866. }
  6867. }
  6868. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6869. }
  6870. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6871. {
  6872. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6873. {
  6874. tempIndex = ((gun_index==2) ? 1: 0);
  6875. }
  6876. else
  6877. {
  6878. tempIndex = gun_index;
  6879. }
  6880. for (int index = 0; index < GB_QUANTITY; index++)
  6881. {
  6882. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6883. {
  6884. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6885. }
  6886. }
  6887. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6888. }
  6889. else if(gunType[gun_index] == GUN_TYPE_DO)
  6890. {
  6891. tempIndex = gun_index;
  6892. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6893. {
  6894. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6895. {
  6896. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6897. }
  6898. }
  6899. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6900. }
  6901. else
  6902. {
  6903. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6904. {
  6905. tempIndex = 2;
  6906. }
  6907. else
  6908. {
  6909. tempIndex = gun_index;
  6910. }
  6911. for (int index = 0; index < AC_QUANTITY; index++)
  6912. {
  6913. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6914. {
  6915. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6916. }
  6917. }
  6918. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6919. }
  6920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6921. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6922. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6923. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6924. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6925. }
  6926. //***********************************************(6)SOC******************************************************/
  6927. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6928. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6929. (dataType == ReadingContext_Trigger))
  6930. {
  6931. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6932. {
  6933. //idx_sample=5;
  6934. //sampledValue = NULL;
  6935. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6936. {
  6937. tempIndex = ((gun_index==2) ? 1: 0);
  6938. }
  6939. else
  6940. {
  6941. tempIndex = gun_index;
  6942. }
  6943. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6944. {
  6945. //tempIndex = ((gun_index==2) ? 1: 0);
  6946. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6947. {
  6948. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6949. {
  6950. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6951. }
  6952. }
  6953. }
  6954. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6955. {
  6956. //tempIndex = ((gun_index==2) ? 1: 0);
  6957. for (int index = 0; index < CCS_QUANTITY; index++)
  6958. {
  6959. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6960. {
  6961. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6962. }
  6963. }
  6964. }
  6965. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6966. {
  6967. //tempIndex = ((gun_index==2) ? 1: 0);
  6968. for (int index = 0; index < GB_QUANTITY; index++)
  6969. {
  6970. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6971. {
  6972. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6973. }
  6974. }
  6975. }
  6976. else if(gunType[gun_index] == GUN_TYPE_DO)
  6977. {
  6978. //tempIndex = ((gun_index==2) ? 1: 0);
  6979. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6980. {
  6981. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6982. {
  6983. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6984. }
  6985. }
  6986. }
  6987. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6988. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6989. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6990. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6991. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6992. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6993. }
  6994. }
  6995. //********************************(7)Current.Import L2************************************************/
  6996. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6997. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6998. (dataType == ReadingContext_Trigger))
  6999. {
  7000. // Only for AC 3 phase
  7001. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7002. {
  7003. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7004. {
  7005. tempIndex = 2;
  7006. }
  7007. else
  7008. {
  7009. tempIndex = gun_index;
  7010. }
  7011. for (int index = 0; index < AC_QUANTITY; index++)
  7012. {
  7013. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7014. {
  7015. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7016. }
  7017. }
  7018. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7019. }
  7020. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7021. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7022. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7023. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7024. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7025. }
  7026. //********************************(8)Current.Import L3************************************************/
  7027. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7028. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7029. (dataType == ReadingContext_Trigger))
  7030. {
  7031. // Only for AC 3 phase
  7032. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7033. {
  7034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7035. {
  7036. tempIndex = 2;
  7037. }
  7038. else
  7039. {
  7040. tempIndex = gun_index;
  7041. }
  7042. for (int index = 0; index < AC_QUANTITY; index++)
  7043. {
  7044. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7045. {
  7046. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7047. }
  7048. }
  7049. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7050. }
  7051. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7052. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7053. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7054. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7055. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7056. }
  7057. //***********************************************(9)VOLTAGE L2******************************************************/
  7058. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7059. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7060. (dataType == ReadingContext_Trigger))
  7061. {
  7062. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7063. {
  7064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7065. {
  7066. tempIndex = 2;
  7067. }
  7068. else
  7069. {
  7070. tempIndex = gun_index;
  7071. }
  7072. for (int index = 0; index < AC_QUANTITY; index++)
  7073. {
  7074. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7075. {
  7076. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7077. }
  7078. }
  7079. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7080. }
  7081. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7082. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7083. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7084. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7085. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7086. }
  7087. //***********************************************(10)VOLTAGE L3******************************************************/
  7088. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7089. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7090. (dataType == ReadingContext_Trigger))
  7091. {
  7092. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7093. {
  7094. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7095. {
  7096. tempIndex = 2;
  7097. }
  7098. else
  7099. {
  7100. tempIndex = gun_index;
  7101. }
  7102. for (int index = 0; index < AC_QUANTITY; index++)
  7103. {
  7104. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7105. {
  7106. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7107. }
  7108. }
  7109. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7110. }
  7111. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7112. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7113. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7114. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7115. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7116. }
  7117. //***********************************************(11)Current.Offered******************************************************/
  7118. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7119. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7120. (dataType == ReadingContext_Trigger))
  7121. {
  7122. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7123. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7124. {
  7125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7126. {
  7127. tempIndex = ((gun_index==2) ? 1: 0);
  7128. }
  7129. else
  7130. {
  7131. tempIndex = gun_index;
  7132. }
  7133. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7134. {
  7135. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7136. {
  7137. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  7138. }
  7139. } // END OF FOR CHAdeMO_QUANTITY
  7140. }
  7141. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7142. {
  7143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7144. {
  7145. tempIndex = ((gun_index==2) ? 1: 0);
  7146. }
  7147. else
  7148. {
  7149. tempIndex = gun_index;
  7150. }
  7151. for (int index = 0; index < CCS_QUANTITY; index++)
  7152. {
  7153. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7154. {
  7155. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  7156. }
  7157. } // END OF CCS_QUANTITY
  7158. }
  7159. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7160. {
  7161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7162. {
  7163. tempIndex = ((gun_index==2) ? 1: 0);
  7164. }
  7165. else
  7166. {
  7167. tempIndex = gun_index;
  7168. }
  7169. for (int index = 0; index < GB_QUANTITY; index++)
  7170. {
  7171. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7172. {
  7173. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  7174. }
  7175. } // END OF GB_QUANTITY
  7176. }
  7177. else if(gunType[gun_index] == GUN_TYPE_DO)
  7178. {
  7179. tempIndex = gun_index;
  7180. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7181. {
  7182. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7183. {
  7184. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  7185. }
  7186. }
  7187. }
  7188. else
  7189. {
  7190. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7191. {
  7192. tempIndex = 2;
  7193. }
  7194. else
  7195. {
  7196. tempIndex = gun_index;
  7197. }
  7198. for (int index = 0; index < AC_QUANTITY; index++)
  7199. {
  7200. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7201. {
  7202. uint16_t currentOffer;
  7203. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7204. {
  7205. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7206. }
  7207. else
  7208. {
  7209. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7210. }
  7211. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7212. }
  7213. }
  7214. }
  7215. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7216. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7217. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7218. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7219. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7220. }
  7221. //***********************************************(12)Power.Offered******************************************************/
  7222. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7223. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7224. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7225. {
  7226. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7227. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7228. {
  7229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7230. {
  7231. tempIndex = ((gun_index==2) ? 1: 0);
  7232. }
  7233. else
  7234. {
  7235. tempIndex = gun_index;
  7236. }
  7237. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7238. {
  7239. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7240. {
  7241. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7242. }
  7243. } // END OF FOR CHAdeMO_QUANTITY
  7244. }
  7245. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7246. {
  7247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7248. {
  7249. tempIndex = ((gun_index==2) ? 1: 0);
  7250. }
  7251. else
  7252. {
  7253. tempIndex = gun_index;
  7254. }
  7255. for (int index = 0; index < CCS_QUANTITY; index++)
  7256. {
  7257. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7258. {
  7259. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7260. }
  7261. } // END OF CCS_QUANTITY
  7262. }
  7263. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7264. {
  7265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7266. {
  7267. tempIndex = ((gun_index==2) ? 1: 0);
  7268. }
  7269. else
  7270. {
  7271. tempIndex = gun_index;
  7272. }
  7273. for (int index = 0; index < GB_QUANTITY; index++)
  7274. {
  7275. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7276. {
  7277. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7278. }
  7279. } // END OF GB_QUANTITY
  7280. }
  7281. else if(gunType[gun_index] == GUN_TYPE_DO)
  7282. {
  7283. tempIndex = gun_index;
  7284. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7285. {
  7286. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7287. {
  7288. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7289. }
  7290. }
  7291. }
  7292. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7293. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7294. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7295. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7296. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7297. }
  7298. // Message create ====================================================================================================
  7299. if(TRUE)
  7300. {
  7301. json_object *MeterValueReq = json_object_new_object();
  7302. json_object *MeterValues = json_object_new_array();
  7303. json_object *sampledValues = json_object_new_array();
  7304. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7305. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7306. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7307. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7308. {
  7309. json_object *MeterValue = json_object_new_object();
  7310. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7311. {
  7312. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7313. {
  7314. json_object *sampledValue = json_object_new_object();
  7315. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7316. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7317. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7318. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7319. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7320. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7321. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7322. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7323. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7324. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7325. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7326. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7327. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7328. json_object_array_add(sampledValues, sampledValue);
  7329. }
  7330. }
  7331. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7332. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7333. json_object_array_add(MeterValues, MeterValue);
  7334. }
  7335. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7336. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7337. ,gun_index + 1
  7338. ,MESSAGE_TYPE_CALL
  7339. ,guid
  7340. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7341. json_object_put(MeterValueReq);
  7342. }
  7343. // Put request guid to hash map
  7344. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7345. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  7346. {
  7347. result = PASS;
  7348. //DEBUG_INFO("MeterValues mapitem pass\n");
  7349. }
  7350. if((dataType != ReadingContext_Trigger) &&
  7351. (dataType != ReadingContext_Sample_Clock) &&
  7352. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7353. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7354. else
  7355. {
  7356. if(FirstHeartBeat)
  7357. LWS_Send(queuedata +2);
  7358. }
  7359. return result;
  7360. }
  7361. int sendLogStatusNotificationRequest(char *status)
  7362. {
  7363. mtrace();
  7364. int result = PASS;
  7365. char message[4096]={0};
  7366. char guid[37]={0};
  7367. char tempdata[128]={0};
  7368. json_object *LogStatusNotification = json_object_new_object();
  7369. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7370. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7371. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7372. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7373. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7374. random_uuid(guid);
  7375. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7376. json_object_put(LogStatusNotification);
  7377. LWS_Send(message);
  7378. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7379. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7380. {
  7381. result = PASS;
  7382. }
  7383. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7384. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7385. return result;
  7386. }
  7387. int sendSecurityEventNotificationRequest()
  7388. {
  7389. mtrace();
  7390. int result = PASS;
  7391. char message[4096]={0};
  7392. char guid[37]={0};
  7393. char tempdata[128]={0};
  7394. json_object *SecurityEventNotification = json_object_new_object();
  7395. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7396. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7397. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7398. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7399. random_uuid(guid);
  7400. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7401. json_object_put(SecurityEventNotification);
  7402. LWS_Send(message);
  7403. sprintf(tempdata, "SecurityEventNotification,0");
  7404. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7405. {
  7406. result = PASS;
  7407. }
  7408. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7409. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7410. return result;
  7411. }
  7412. int sendSignCertificateRequest()
  7413. {
  7414. mtrace();
  7415. int result = PASS;
  7416. char message[4096]={0};
  7417. char guid[37]={0};
  7418. char tempdata[128]={0};
  7419. json_object *SignCertificate = json_object_new_object();
  7420. DEBUG_INFO("sendSignCertificateRequest...\n");
  7421. // Read csr file content
  7422. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7423. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7424. char *line = NULL;
  7425. size_t len = 0;
  7426. while(getline(&line, &len, fp) != -1)
  7427. {
  7428. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7429. {
  7430. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7431. }
  7432. }
  7433. fclose(fp);
  7434. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7435. random_uuid(guid);
  7436. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7437. json_object_put(SignCertificate);
  7438. LWS_Send(message);
  7439. sprintf(tempdata, "SignCertificate,0");
  7440. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7441. {
  7442. result = PASS;
  7443. }
  7444. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7445. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7446. return result;
  7447. }
  7448. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7449. {
  7450. mtrace();
  7451. int result = PASS;
  7452. char message[110]={0};
  7453. char guid[37]={0};
  7454. char tempdata[65]={0};
  7455. json_object *FirmwareStatusNotification = json_object_new_object();
  7456. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7457. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7458. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7459. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7460. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7461. random_uuid(guid);
  7462. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7463. json_object_put(FirmwareStatusNotification);
  7464. LWS_Send(message);
  7465. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7466. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7467. {
  7468. result = PASS;
  7469. }
  7470. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7471. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7472. return result;
  7473. }
  7474. //==========================================
  7475. // send confirm routine
  7476. //==========================================
  7477. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7478. {
  7479. mtrace();
  7480. int result = FAIL;
  7481. char message[100]={0};
  7482. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7483. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7484. LWS_Send(message);
  7485. result = TRUE;
  7486. return result;
  7487. }
  7488. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7489. {
  7490. mtrace();
  7491. int result = FAIL;
  7492. char message[100]={0};
  7493. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7494. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7495. LWS_Send(message);
  7496. result = TRUE;
  7497. return result;
  7498. }
  7499. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7500. {
  7501. mtrace();
  7502. int result = FAIL;
  7503. char message[100]={0};
  7504. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7505. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7506. LWS_Send(message);
  7507. result = TRUE;
  7508. return result;
  7509. }
  7510. int sendClearCacheConfirmation(char *uuid,char *payload)
  7511. {
  7512. mtrace();
  7513. int result = FAIL;
  7514. char message[500]={0};
  7515. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7516. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7517. LWS_Send(message);
  7518. return result;
  7519. }
  7520. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7521. {
  7522. mtrace();
  7523. int result = FAIL;
  7524. char message[500]={0};
  7525. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7526. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7527. LWS_Send(message);
  7528. return result;
  7529. }
  7530. int sendDataTransferConfirmation(char *uuid,char *payload)
  7531. {
  7532. mtrace();
  7533. char statusStr[20]={0};
  7534. char dataStr[10]={0};
  7535. char sstr[20]={0};
  7536. int c = 0;
  7537. char *loc;
  7538. int result = FAIL;
  7539. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7540. /**********************status**************************/
  7541. loc = strstr(payload, "status");
  7542. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7543. c = 0;
  7544. while (loc[3+strlen("status")+c] != '\"')
  7545. {
  7546. sstr[c] = loc[3+strlen("status")+c];
  7547. c++;
  7548. }
  7549. sstr[c] = '\0';
  7550. strcpy(statusStr, sstr);
  7551. /**********************data**************************/
  7552. loc = strstr(payload, "data");
  7553. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7554. c = 0;
  7555. while (loc[3+strlen("data")+c] != '\"')
  7556. {
  7557. sstr[c] = loc[3+strlen("data")+c];
  7558. c++;
  7559. }
  7560. sstr[c] = '\0';
  7561. strcpy(dataStr, sstr);
  7562. return result;
  7563. }
  7564. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7565. {
  7566. mtrace();
  7567. int result = FAIL;
  7568. char message[1000]={0};
  7569. int CompositeScheduleIndex = 0;
  7570. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7571. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7572. if(nPeriod == 0)
  7573. {
  7574. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7575. {
  7576. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7577. ,MESSAGE_TYPE_CALLRESULT
  7578. ,uuid
  7579. ,payload
  7580. ,connectorIdInt);
  7581. }
  7582. else
  7583. {
  7584. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7585. ,MESSAGE_TYPE_CALLRESULT
  7586. ,uuid
  7587. ,payload
  7588. ,connectorIdInt
  7589. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7590. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7591. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7592. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7593. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7594. }
  7595. }
  7596. else
  7597. {
  7598. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7599. ,MESSAGE_TYPE_CALLRESULT
  7600. ,uuid
  7601. ,payload
  7602. ,connectorIdInt
  7603. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7604. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7605. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7606. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7607. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7608. {
  7609. if (idx_sample == 0)
  7610. {
  7611. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7612. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7613. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7614. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7615. }
  7616. else
  7617. {
  7618. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7619. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7620. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7621. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7622. }
  7623. }
  7624. sprintf(message + strlen(message), "]}}]");
  7625. }
  7626. LWS_Send(message);
  7627. result = TRUE;
  7628. return result;
  7629. }
  7630. int sendGetConfigurationConfirmation(char *uuid)
  7631. {
  7632. mtrace();
  7633. int result = FAIL;
  7634. int MaxKeySupported = 0;
  7635. int sentConfigurationNumber= 0;
  7636. int sentunConfigurationNumber= 0;
  7637. char message[1024*10]={0};
  7638. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7639. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7640. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7641. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7642. ,MESSAGE_TYPE_CALLRESULT
  7643. ,uuid );
  7644. //configuration key
  7645. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7646. {
  7647. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7648. {
  7649. if (sentConfigurationNumber == 0)
  7650. {
  7651. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7652. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7653. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7654. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7655. }
  7656. else
  7657. {
  7658. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7659. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7660. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7661. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7662. }
  7663. sentConfigurationNumber = sentConfigurationNumber + 1;
  7664. }
  7665. }
  7666. sprintf(message + strlen(message), "]");
  7667. if(UnknownKeynum != 0)
  7668. {
  7669. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7670. //unkown key
  7671. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7672. {
  7673. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7674. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7675. if(sentunConfigurationNumber == 0)
  7676. {
  7677. sprintf(message + strlen(message), "\"%s\""
  7678. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7679. }
  7680. else
  7681. {
  7682. sprintf(message + strlen(message), ",\"%s\""
  7683. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7684. }
  7685. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7686. }
  7687. sprintf(message + strlen(message), "]");
  7688. }
  7689. sprintf(message + strlen(message), "}]");
  7690. LWS_Send(message);
  7691. return result;
  7692. }
  7693. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7694. {
  7695. mtrace();
  7696. int result = FAIL;
  7697. char message[400]={0};
  7698. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7699. if(strcmp(payload,"")==0)
  7700. {
  7701. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7702. }
  7703. else
  7704. {
  7705. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7706. }
  7707. LWS_Send(message);
  7708. result = TRUE;
  7709. return result;
  7710. }
  7711. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7712. {
  7713. mtrace();
  7714. int result = FAIL;
  7715. char message[80]={0};
  7716. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7717. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7718. LWS_Send(message);
  7719. result = TRUE;
  7720. return result;
  7721. }
  7722. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7723. {
  7724. mtrace();
  7725. int result = FAIL;
  7726. char message[80]={0};
  7727. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7728. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7729. LWS_Send(message);
  7730. result = TRUE;
  7731. return result;
  7732. }
  7733. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7734. {
  7735. mtrace();
  7736. int result = FAIL;
  7737. char message[80]={0};
  7738. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7739. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7740. LWS_Send(message);
  7741. result = TRUE;
  7742. return result;
  7743. }
  7744. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7745. {
  7746. mtrace();
  7747. int result = FAIL;
  7748. char message[80]={0};
  7749. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7750. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7751. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7752. LWS_Send(message);
  7753. result = TRUE;
  7754. return result;
  7755. }
  7756. int sendResetConfirmation(char *uuid,char *payload)
  7757. {
  7758. mtrace();
  7759. int result = FAIL;
  7760. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7761. char message[80]={0};
  7762. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7763. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7764. LWS_Send(message);
  7765. result = TRUE;
  7766. return result;
  7767. }
  7768. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7769. {
  7770. mtrace();
  7771. int result = FAIL;
  7772. char message[500]={0};
  7773. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7774. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7775. LWS_Send(message);
  7776. result = TRUE;
  7777. return result;
  7778. }
  7779. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7780. {
  7781. mtrace();
  7782. int result = FAIL;
  7783. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7784. char message[80]={0};
  7785. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7786. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7787. LWS_Send(message);
  7788. result = TRUE;
  7789. return result;
  7790. }
  7791. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7792. {
  7793. mtrace();
  7794. int result = FAIL;
  7795. char message[80]={0};
  7796. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7797. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7798. LWS_Send(message);
  7799. result = TRUE;
  7800. return result;
  7801. }
  7802. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7803. {
  7804. mtrace();
  7805. int result = FAIL;
  7806. char message[80]={0};
  7807. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7808. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7809. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7810. LWS_Send(message);
  7811. result = TRUE;
  7812. return result;
  7813. }
  7814. int sendUpdateFirmwareConfirmation(char *uuid)
  7815. {
  7816. mtrace();
  7817. int result = FAIL;
  7818. char message[60]={0};
  7819. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7820. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7821. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7822. LWS_Send(message);
  7823. result = TRUE;
  7824. return result;
  7825. }
  7826. int sendCertificateSignedConfirmation(char *uuid)
  7827. {
  7828. mtrace();
  7829. int result = PASS;
  7830. char message[4096]={0};
  7831. json_object *CertificateSigned = json_object_new_object();
  7832. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7833. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7834. sprintf(message,"[%d,\"%s\",%s]"
  7835. ,MESSAGE_TYPE_CALLRESULT
  7836. ,uuid
  7837. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7838. json_object_put(CertificateSigned);
  7839. LWS_Send(message);
  7840. return result;
  7841. }
  7842. int sendDeleteCertificateConfirmation(char *uuid)
  7843. {
  7844. mtrace();
  7845. int result = PASS;
  7846. char message[4096]={0};
  7847. json_object *DeleteCertificate = json_object_new_object();
  7848. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7849. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7850. sprintf(message,"[%d,\"%s\",%s]"
  7851. ,MESSAGE_TYPE_CALLRESULT
  7852. ,uuid
  7853. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7854. json_object_put(DeleteCertificate);
  7855. LWS_Send(message);
  7856. return result;
  7857. }
  7858. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7859. {
  7860. mtrace();
  7861. int result = PASS;
  7862. char message[4096]={0};
  7863. json_object *ExtendedTriggerMessage = json_object_new_object();
  7864. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7865. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7866. sprintf(message,"[%d,\"%s\",%s]"
  7867. ,MESSAGE_TYPE_CALLRESULT
  7868. ,uuid
  7869. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7870. json_object_put(ExtendedTriggerMessage);
  7871. LWS_Send(message);
  7872. return result;
  7873. }
  7874. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7875. {
  7876. mtrace();
  7877. int result = PASS;
  7878. char message[4096]={0};
  7879. json_object *GetInstalledCertificateIds = json_object_new_object();
  7880. json_object *certificateHashDataDatas = json_object_new_array();
  7881. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7882. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7883. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7884. {
  7885. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7886. {
  7887. json_object *certificateHashData = json_object_new_object();
  7888. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7889. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7890. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7891. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7892. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7893. }
  7894. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7895. }
  7896. else
  7897. {
  7898. json_object_put(certificateHashDataDatas);
  7899. }
  7900. sprintf(message,"[%d,\"%s\",%s]"
  7901. ,MESSAGE_TYPE_CALLRESULT
  7902. ,uuid
  7903. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7904. json_object_put(GetInstalledCertificateIds);
  7905. LWS_Send(message);
  7906. return result;
  7907. }
  7908. int sendGetLogConfirmation(char *uuid)
  7909. {
  7910. mtrace();
  7911. int result = PASS;
  7912. char message[4096]={0};
  7913. json_object *GetLog = json_object_new_object();
  7914. DEBUG_INFO("sendGetLogConfirmation...\n");
  7915. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7916. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7917. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7918. sprintf(message,"[%d,\"%s\",%s]"
  7919. ,MESSAGE_TYPE_CALLRESULT
  7920. ,uuid
  7921. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7922. json_object_put(GetLog);
  7923. LWS_Send(message);
  7924. return result;
  7925. }
  7926. int sendInstallCertificateConfirmation(char *uuid)
  7927. {
  7928. mtrace();
  7929. int result = PASS;
  7930. char message[4096]={0};
  7931. json_object *InstallCertificate = json_object_new_object();
  7932. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7933. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7934. sprintf(message,"[%d,\"%s\",%s]"
  7935. ,MESSAGE_TYPE_CALLRESULT
  7936. ,uuid
  7937. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7938. json_object_put(InstallCertificate);
  7939. LWS_Send(message);
  7940. return result;
  7941. }
  7942. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7943. {
  7944. mtrace();
  7945. int result = PASS;
  7946. char message[4096]={0};
  7947. json_object *SignedUpdateFirmware = json_object_new_object();
  7948. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7949. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7950. sprintf(message,"[%d,\"%s\",%s]"
  7951. ,MESSAGE_TYPE_CALLRESULT
  7952. ,uuid
  7953. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7954. json_object_put(SignedUpdateFirmware);
  7955. LWS_Send(message);
  7956. return result;
  7957. }
  7958. int sendUnknownConfirmation(char *uuid)
  7959. {
  7960. mtrace();
  7961. int result = PASS;
  7962. char message[256]={0};
  7963. DEBUG_INFO("sendUnknownConfirmation...\n");
  7964. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7965. LWS_Send(message);
  7966. return result;
  7967. }
  7968. //==========================================
  7969. // Handle server request routine Start
  7970. //==========================================
  7971. int handleCancelReservationRequest(char *uuid, char *payload)
  7972. {
  7973. mtrace();
  7974. int result = FAIL;
  7975. int gunNO = 0;
  7976. int reservationIdInt = -1;
  7977. char comfirmstr[20];
  7978. DEBUG_INFO("handleCancelReservationRequest...\n");
  7979. json_object *CancelReservation;
  7980. CancelReservation = json_tokener_parse(payload);
  7981. if(!is_error(CancelReservation))
  7982. {
  7983. // Required data
  7984. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7985. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7986. }
  7987. json_object_put(CancelReservation);
  7988. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7989. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7990. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7991. if(reservationIdInt != -1)
  7992. {
  7993. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7994. //check Transaction active
  7995. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7996. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7997. {
  7998. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7999. {
  8000. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8001. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8002. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8003. {
  8004. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8005. }
  8006. else
  8007. {
  8008. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8009. }
  8010. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8011. goto end;
  8012. }
  8013. }
  8014. for (int index = 0; index < CCS_QUANTITY; index++)
  8015. {
  8016. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8017. {
  8018. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8019. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8020. if(gunType[2] == GUN_TYPE_CCS)
  8021. {
  8022. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8023. }
  8024. else
  8025. {
  8026. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8027. }
  8028. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8029. goto end;
  8030. }
  8031. }
  8032. for (int index = 0; index < GB_QUANTITY; index++)
  8033. {
  8034. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8035. {
  8036. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8037. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8038. if(gunType[2] == GUN_TYPE_GBT)
  8039. {
  8040. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8041. }
  8042. else
  8043. {
  8044. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8045. }
  8046. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8047. goto end;
  8048. }
  8049. }
  8050. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8051. {
  8052. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8053. {
  8054. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8055. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8056. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8057. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8058. goto end;
  8059. }
  8060. }
  8061. for (int index = 0; index < AC_QUANTITY; index++)
  8062. {
  8063. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8064. {
  8065. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8066. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8067. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8068. {
  8069. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8070. }
  8071. else
  8072. {
  8073. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8074. }
  8075. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8076. goto end;
  8077. }
  8078. }
  8079. }
  8080. //The reservationId does NOT match the reservationId
  8081. sendCancelReservationConfirmation(uuid, comfirmstr);
  8082. end:
  8083. // Fill in ocpp packet uuid
  8084. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  8085. return result;
  8086. }
  8087. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8088. {
  8089. mtrace();
  8090. int result = FAIL;
  8091. int gunIndex = -1;
  8092. char typeStr[16]={0};
  8093. char comfirmstr[20];
  8094. int specificId = FALSE;
  8095. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8096. json_object *ChangeAvailability;
  8097. ChangeAvailability = json_tokener_parse(payload);
  8098. if(!is_error(ChangeAvailability))
  8099. {
  8100. // Required data
  8101. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8102. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8103. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8104. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8105. }
  8106. json_object_put(ChangeAvailability);
  8107. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8108. {
  8109. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8110. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8111. }
  8112. else if(gunIndex == 0)
  8113. {
  8114. for(int i=0; i < gunTotalNumber; i++)
  8115. {
  8116. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  8117. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  8118. }
  8119. }
  8120. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8121. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8122. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8123. {
  8124. specificId = TRUE;
  8125. }
  8126. if(specificId == FALSE)
  8127. goto end;
  8128. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8129. {
  8130. //----------------------gunIndex is 0 ------------------------------------------------//
  8131. if(gunIndex == 0)
  8132. {
  8133. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8134. {
  8135. for(int i=0; i < gunTotalNumber; i++)
  8136. {
  8137. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8138. {
  8139. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8140. {
  8141. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8142. {
  8143. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8144. goto end;
  8145. }
  8146. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8147. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8148. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8149. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8150. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8151. {
  8152. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8153. goto end;
  8154. }
  8155. }
  8156. }//END FOR CHAdeMO_QUANTITY
  8157. for (int index = 0; index < CCS_QUANTITY; index++)
  8158. {
  8159. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8160. {
  8161. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8162. {
  8163. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8164. goto end;
  8165. }
  8166. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8167. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8168. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8169. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8170. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8171. {
  8172. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8173. goto end;
  8174. }
  8175. }
  8176. }//END FOR CCS_QUANTITY
  8177. for (int index = 0; index < GB_QUANTITY; index++)
  8178. {
  8179. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8180. {
  8181. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8182. {
  8183. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8184. goto end;
  8185. }
  8186. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8187. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8188. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8189. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8190. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8191. {
  8192. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8193. goto end;
  8194. }
  8195. }
  8196. }// END FOR GB_QUANTITY
  8197. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8198. {
  8199. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8200. {
  8201. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8202. {
  8203. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8204. goto end;
  8205. }
  8206. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8207. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8208. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8209. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8210. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8211. {
  8212. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8213. goto end;
  8214. }
  8215. }
  8216. }// END FOR GENERAL_GUN_QUANTITY
  8217. for (int index = 0; index < AC_QUANTITY; index++)
  8218. {
  8219. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8220. {
  8221. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8222. {
  8223. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8224. goto end;
  8225. }
  8226. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8227. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8228. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8229. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8230. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8231. {
  8232. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8233. goto end;
  8234. }
  8235. }
  8236. }//END FOR AC_QUANTITY
  8237. }// END FOR gunTotalNumber
  8238. }
  8239. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8240. {
  8241. for(int i=0; i < gunTotalNumber; i++)
  8242. {
  8243. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8244. {
  8245. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8246. goto end;
  8247. }
  8248. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8249. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8250. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8251. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8252. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8253. {
  8254. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8255. goto end;
  8256. }
  8257. }
  8258. }
  8259. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8260. goto end;
  8261. }
  8262. //----------------------gunIndex is not 0 ------------------------------------------------//
  8263. //check Transaction active
  8264. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8265. {
  8266. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8267. {
  8268. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8269. {
  8270. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8271. goto end;
  8272. }
  8273. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8274. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8275. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8276. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8277. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8278. {
  8279. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8280. goto end;
  8281. }
  8282. else
  8283. {
  8284. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8285. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8286. goto end;
  8287. }
  8288. }
  8289. }//END FOR CHAdeMO_QUANTITY
  8290. for (int index = 0; index < CCS_QUANTITY; index++)
  8291. {
  8292. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8293. {
  8294. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8295. {
  8296. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8297. goto end;
  8298. }
  8299. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8300. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8301. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8302. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8303. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8304. {
  8305. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8306. goto end;
  8307. }
  8308. else
  8309. {
  8310. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8311. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8312. goto end;
  8313. }
  8314. }
  8315. }//END FOR CCS_QUANTITY
  8316. for (int index = 0; index < GB_QUANTITY; index++)
  8317. {
  8318. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8319. {
  8320. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8321. {
  8322. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8323. goto end;
  8324. }
  8325. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8326. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8327. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8328. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8329. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8330. {
  8331. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8332. goto end;
  8333. }
  8334. else
  8335. {
  8336. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8337. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8338. goto end;
  8339. }
  8340. }
  8341. }// END FOR GB_QUANTITY
  8342. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8343. {
  8344. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8345. {
  8346. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8347. {
  8348. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8349. goto end;
  8350. }
  8351. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8352. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8353. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8354. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8355. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8356. {
  8357. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8358. goto end;
  8359. }
  8360. else
  8361. {
  8362. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8363. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8364. goto end;
  8365. }
  8366. }
  8367. }// END FOR GENERAL_GUN_QUANTITY
  8368. for (int index = 0; index < AC_QUANTITY; index++)
  8369. {
  8370. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8371. {
  8372. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8373. {
  8374. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8375. goto end;
  8376. }
  8377. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8378. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8379. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8380. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8381. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8382. {
  8383. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8384. goto end;
  8385. }
  8386. else
  8387. {
  8388. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8389. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8390. goto end;
  8391. }
  8392. }
  8393. }//END FOR AC_QUANTITY
  8394. }//END FOR AvailabilityTypeStr[Inoperative]
  8395. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8396. {
  8397. //----------------------gunIndex is 0 ------------------------------------------------//
  8398. if(gunIndex == 0)
  8399. {
  8400. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8401. {
  8402. for(int i=0; i < gunTotalNumber; i++)
  8403. {
  8404. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8405. {
  8406. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8407. {
  8408. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8409. goto end;
  8410. }
  8411. }//END FOR CHAdeMO_QUANTITY
  8412. for (int index = 0; index < CCS_QUANTITY; index++)
  8413. {
  8414. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8415. {
  8416. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8417. goto end;
  8418. }
  8419. }//END FOR CCS_QUANTITY
  8420. for (int index = 0; index < GB_QUANTITY; index++)
  8421. {
  8422. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8423. {
  8424. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8425. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8426. goto end;
  8427. }
  8428. }// END FOR GB_QUANTITY
  8429. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8430. {
  8431. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8432. {
  8433. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8435. goto end;
  8436. }
  8437. }// END FOR GENERAL_GUN_QUANTITY
  8438. for (int index = 0; index < AC_QUANTITY; index++)
  8439. {
  8440. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8441. {
  8442. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8443. goto end;
  8444. }
  8445. }//END FOR CHAdeMO_QUANTITY
  8446. }// END FOR gunTotalNumber
  8447. }
  8448. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8449. {
  8450. for(int i=0; i < gunTotalNumber; i++)
  8451. {
  8452. for (int index = 0; index < AC_QUANTITY; index++)
  8453. {
  8454. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8455. {
  8456. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8457. goto end;
  8458. }
  8459. }//END FOR CHAdeMO_QUANTITY
  8460. } // END FOR gunTotalNumber
  8461. }
  8462. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8463. goto end;
  8464. }
  8465. //----------------------gunIndex is not 0 ------------------------------------------------//
  8466. //check Transaction active
  8467. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8468. {
  8469. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8470. {
  8471. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8472. goto end;
  8473. }
  8474. }//END FOR CHAdeMO_QUANTITY
  8475. for (int index = 0; index < CCS_QUANTITY; index++)
  8476. {
  8477. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8478. {
  8479. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8480. goto end;
  8481. }
  8482. }//END FOR CCS_QUANTITY
  8483. for (int index = 0; index < GB_QUANTITY; index++)
  8484. {
  8485. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8486. {
  8487. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8488. goto end;
  8489. }
  8490. }// END FOR GB_QUANTITY
  8491. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8492. {
  8493. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8494. {
  8495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8496. goto end;
  8497. }
  8498. }// END FOR GENERAL_GUN_QUANTITY
  8499. for (int index = 0; index < AC_QUANTITY; index++)
  8500. {
  8501. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8502. {
  8503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8504. goto end;
  8505. }
  8506. }//END FOR AC_QUANTITY
  8507. }//END FOR AvailabilityTypeStr[Operative]
  8508. end:
  8509. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8510. {
  8511. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8512. }
  8513. else
  8514. {
  8515. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8516. }
  8517. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8518. {
  8519. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8520. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8521. }
  8522. else if(gunIndex == 0)
  8523. {
  8524. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8525. {
  8526. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8527. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8528. }
  8529. }
  8530. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8531. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8532. return result;
  8533. }
  8534. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8535. {
  8536. mtrace();
  8537. int valueInvalid = NO;
  8538. int result = FAIL;
  8539. char keystr[40]={0};
  8540. char valuestr[501]={0}; //value should be limited in 500 bytes
  8541. char comfirmstr[20]={0};
  8542. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8543. json_object *ChangeConfiguration;
  8544. ChangeConfiguration = json_tokener_parse(payload);
  8545. if(!is_error(ChangeConfiguration))
  8546. {
  8547. // Required data
  8548. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8549. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8550. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8551. {
  8552. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8553. }
  8554. else
  8555. {
  8556. valueInvalid = YES;
  8557. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8558. }
  8559. }
  8560. json_object_put(ChangeConfiguration);
  8561. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8562. {
  8563. DEBUG_ERROR("Payload is null or not accepted.\n");
  8564. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8565. }
  8566. else
  8567. {
  8568. int status = setKeyValue(keystr, valuestr);
  8569. switch(status)
  8570. {
  8571. case ConfigurationStatus_Accepted:
  8572. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8573. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8574. StoreConfigurationTable();
  8575. break;
  8576. case RebootRequired:
  8577. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8578. StoreConfigurationTable();
  8579. break;
  8580. case NotSupported:
  8581. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8582. break;
  8583. case ConfigurationStatus_Rejected:
  8584. default:
  8585. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8586. break;
  8587. }
  8588. }
  8589. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8590. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8591. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8592. {
  8593. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8594. SetOcppConnStatus(FALSE);
  8595. }
  8596. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8597. {
  8598. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8599. }
  8600. return result;
  8601. }
  8602. int handleClearCacheRequest(char *uuid, char *payload)
  8603. {
  8604. mtrace();
  8605. int result = FAIL;
  8606. char comfirmstr[20];
  8607. char rmFileCmd[100]={0};
  8608. struct stat stats;
  8609. DEBUG_INFO("handleClearCacheRequest...\n");
  8610. stat("/Storage/OCPP_PH", &stats);
  8611. // Check for directory existence
  8612. if (S_ISDIR(stats.st_mode) == 1)
  8613. {}
  8614. else
  8615. {
  8616. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8617. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8618. system(rmFileCmd);
  8619. }
  8620. if(OCPP_cleanLocalCache())
  8621. {
  8622. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8623. }
  8624. else
  8625. {
  8626. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8627. }
  8628. sendClearCacheConfirmation(uuid, comfirmstr);
  8629. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8630. return result;
  8631. }
  8632. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8633. {
  8634. mtrace();
  8635. int result = FAIL;
  8636. int resultRename;
  8637. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8638. char chargingProfilePurposeStr[26]={0};
  8639. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8640. char tempchargingProfilePurposeStr[26]={0};
  8641. char str[100]={0};
  8642. char fname[200]={0};
  8643. char comfirmstr[20]={0};
  8644. char word[1600]={0};
  8645. int clearflag = FALSE;
  8646. int chargingProfileIdIsNULL = FALSE;
  8647. int connectorIsNULL = FALSE;
  8648. int chargingProfilePurposeIsNULL = FALSE;
  8649. int stackLevelIsNULL = FALSE;
  8650. //int GotoEnd = FALSE;
  8651. FILE *fptr1, *fptr2;
  8652. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8653. int n_chargingProfile=0;
  8654. int isEmptyFile = FALSE;
  8655. char sLineWord[1600]={0};
  8656. char chargingProfiles[10][100]={0};
  8657. int ChargeProfileCount = 0;
  8658. int ch;
  8659. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8660. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8661. json_object *ClearChargingProfile;
  8662. ClearChargingProfile = json_tokener_parse(payload);
  8663. if(!is_error(ClearChargingProfile))
  8664. {
  8665. // Optional data
  8666. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8667. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8668. else
  8669. chargingProfileIdIsNULL = TRUE;
  8670. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8671. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8672. else
  8673. connectorIsNULL = TRUE;
  8674. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8675. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8676. else
  8677. chargingProfilePurposeIsNULL = TRUE;
  8678. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8679. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8680. else
  8681. stackLevelIsNULL = TRUE;
  8682. }
  8683. json_object_put(ClearChargingProfile);
  8684. if(connectorIsNULL == FALSE)
  8685. {
  8686. switch(connectorIdInt)
  8687. {
  8688. case 0:
  8689. if(chargingProfilePurposeIsNULL == TRUE)
  8690. {
  8691. int l = 0;
  8692. strcpy(fname, ChargePointMaxProfile_JSON);
  8693. if((access(fname,F_OK))!=-1)
  8694. {
  8695. strcpy(chargingProfiles[l], fname);
  8696. l = l + 1;
  8697. }
  8698. strcpy(fname, TxDefaultProfile_0_JSON);
  8699. if((access(fname,F_OK))!=-1)
  8700. {
  8701. strcpy(chargingProfiles[l], fname);
  8702. l = l + 1;
  8703. }
  8704. ChargeProfileCount = l;
  8705. }
  8706. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8707. {
  8708. strcpy(fname, ChargePointMaxProfile_JSON);
  8709. if((access(fname,F_OK))!=-1)
  8710. {
  8711. strcpy(chargingProfiles[0], fname);
  8712. ChargeProfileCount = 1;
  8713. }
  8714. }
  8715. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8716. {
  8717. strcpy(fname, TxDefaultProfile_0_JSON);
  8718. if((access(fname,F_OK))!=-1)
  8719. {
  8720. strcpy(chargingProfiles[0], fname);
  8721. ChargeProfileCount = 1;
  8722. }
  8723. }
  8724. break;
  8725. default:
  8726. if(chargingProfilePurposeIsNULL == TRUE)
  8727. {
  8728. int m = 0;
  8729. memset(fname, 0, ARRAY_SIZE(fname));
  8730. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8731. if((access(fname,F_OK))!=-1)
  8732. {
  8733. strcpy(chargingProfiles[m], fname);
  8734. m = m + 1;
  8735. }
  8736. memset(fname, 0, ARRAY_SIZE(fname));
  8737. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8738. if((access(fname,F_OK))!=-1)
  8739. {
  8740. strcpy(chargingProfiles[m], fname);
  8741. m = m + 1;
  8742. }
  8743. ChargeProfileCount = m;
  8744. }
  8745. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8746. {
  8747. //strcpy(fname, TxDefaultProfile_1_JSON);
  8748. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8749. if((access(fname,F_OK))!=-1)
  8750. {
  8751. strcpy(chargingProfiles[0], fname);
  8752. ChargeProfileCount = 1;
  8753. }
  8754. }
  8755. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8756. {
  8757. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8758. if((access(fname,F_OK))!=-1)
  8759. {
  8760. strcpy(chargingProfiles[0], fname);
  8761. ChargeProfileCount = 1;
  8762. }
  8763. //strcpy(fname, TxProfile_1_JSON);
  8764. }
  8765. //strcpy(fname, ChargePointMaxProfile_JSON );
  8766. break;
  8767. }
  8768. }
  8769. else // Check all Charging Profiles
  8770. {
  8771. int i = 0;
  8772. char fnametemp[200]={0};
  8773. ChargeProfileCount = 0;
  8774. //Check ChargePointMaxProfile.json exit
  8775. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8776. {
  8777. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8778. i = i + 1;
  8779. }
  8780. //Check TxDefaultProfile_0.json exit
  8781. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8782. {
  8783. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8784. i = i + 1;
  8785. }
  8786. //Check TxDefaultProfile_%d.json
  8787. for(int j=1; j <= gunTotalNumber; j++)
  8788. {
  8789. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8790. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8791. if((access(fnametemp,F_OK))!=-1)
  8792. {
  8793. strcpy(chargingProfiles[i], fnametemp);
  8794. i = i + 1;
  8795. }
  8796. }
  8797. //Check TxProfile_%d.json
  8798. for(int j=1; j <= gunTotalNumber; j++)
  8799. {
  8800. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8801. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8802. if((access(fnametemp,F_OK))!=-1)
  8803. {
  8804. strcpy(chargingProfiles[i], fnametemp);
  8805. i = i + 1;
  8806. }
  8807. }
  8808. ChargeProfileCount = i;
  8809. }// End connectorIsNULL is TRUE
  8810. if(ChargeProfileCount == 0)
  8811. {
  8812. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8813. goto end;
  8814. }
  8815. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8816. {
  8817. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8818. goto end;
  8819. }
  8820. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8821. {
  8822. memset(str, 0, ARRAY_SIZE(str));
  8823. // clear temp file
  8824. sprintf(str,"rm -f %s",temp);
  8825. system(str);
  8826. for(int k=0; k < ChargeProfileCount; k++)
  8827. {
  8828. memset(str, 0, ARRAY_SIZE(str));
  8829. //clear file in C
  8830. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8831. system(str);
  8832. }
  8833. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8834. goto end;
  8835. }
  8836. else if(connectorIsNULL == TRUE)
  8837. {
  8838. for(int k=0; k < ChargeProfileCount; k++)
  8839. {
  8840. fptr1 = fopen(chargingProfiles[k], "r");
  8841. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8842. //Check Charging Profile Count
  8843. while(fscanf(fptr1, "%s", word) != EOF)
  8844. {
  8845. //DEBUG_INFO("word=%s\n",word);
  8846. if(strstr(word, "chargingProfileId")!= NULL)
  8847. {
  8848. //DEBUG_INFO("test chargingProfileId \n");
  8849. n_chargingProfile = n_chargingProfile + 1;
  8850. //DEBUG_INFO("chargingProfileId Found\n");
  8851. }
  8852. }
  8853. rewind(fptr1);
  8854. //search Charging Profile Element
  8855. //int i= 0;
  8856. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8857. {
  8858. json_object *tmpProfilee;
  8859. tmpProfilee = json_tokener_parse(sLineWord);
  8860. if(!is_error(tmpProfilee))
  8861. {
  8862. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8863. {
  8864. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8865. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8866. }
  8867. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8868. {
  8869. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8870. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8871. }
  8872. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8873. {
  8874. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8875. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8876. }
  8877. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8878. {
  8879. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8880. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8881. }
  8882. }
  8883. json_object_put(tmpProfilee);
  8884. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8885. {
  8886. //------- not write to fptr2-------//
  8887. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8888. //clearflag = TRUE;
  8889. }
  8890. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8891. {
  8892. //------- not write to fptr2-------//
  8893. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8894. }
  8895. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8896. {
  8897. //------- not write to fptr2-------//
  8898. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8899. }
  8900. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8901. {
  8902. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8903. }
  8904. else
  8905. {
  8906. fprintf(fptr2, sLineWord);//writing data into file
  8907. }
  8908. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8909. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8910. if(clearflag == TRUE)
  8911. {
  8912. fclose(fptr1);
  8913. fclose(fptr2);
  8914. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8915. system(str);
  8916. // clear temp file
  8917. sprintf(str,"rm -f %s",temp);
  8918. system(str);
  8919. }
  8920. else
  8921. {
  8922. fclose(fptr1);
  8923. fclose(fptr2);
  8924. memset(str, 0, ARRAY_SIZE(str));
  8925. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8926. system(str);
  8927. resultRename = rename(temp, chargingProfiles[k]);
  8928. if(resultRename == 0)
  8929. {
  8930. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8931. }
  8932. else
  8933. {
  8934. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8935. }
  8936. if(comfirmstr[0]== 0)
  8937. {
  8938. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8939. }
  8940. //Check chargingProfile is empty file
  8941. /*------ Read the file ----------------*/
  8942. fptr1=fopen(chargingProfiles[k],"r");
  8943. ch=fgetc(fptr1);
  8944. rewind(fptr1);
  8945. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8946. if(ch!=EOF)
  8947. {
  8948. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8949. {
  8950. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8951. if(sLineWord[0]=='\0')
  8952. {
  8953. isEmptyFile = TRUE;
  8954. break;
  8955. }
  8956. else
  8957. {
  8958. isEmptyFile = FALSE;
  8959. break;
  8960. }
  8961. }
  8962. }
  8963. else
  8964. isEmptyFile = TRUE;
  8965. fclose(fptr1);
  8966. if(isEmptyFile == TRUE)
  8967. {
  8968. memset(str, 0, ARRAY_SIZE(str));
  8969. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8970. system(str);
  8971. }
  8972. }
  8973. }// End of while(int k=0; k < ChargePointCount; k++)
  8974. }
  8975. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8976. {
  8977. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8978. for(int k=0; k < ChargeProfileCount; k++)
  8979. {
  8980. fptr1 = fopen(chargingProfiles[k], "r");
  8981. fptr2 = fopen(temp, "w+");
  8982. //Check Charging Profile Count
  8983. while(fscanf(fptr1, "%s", word) != EOF)
  8984. {
  8985. //DEBUG_INFO("word=%s\n",word);
  8986. if(strstr(word, "chargingProfileId")!= NULL)
  8987. {
  8988. n_chargingProfile = n_chargingProfile + 1;
  8989. }
  8990. }
  8991. rewind(fptr1);
  8992. //search Charging Profile Element
  8993. //int i= 0;
  8994. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8995. {
  8996. json_object *tmpProfilee;
  8997. tmpProfilee = json_tokener_parse(sLineWord);
  8998. if(!is_error(tmpProfilee))
  8999. {
  9000. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9001. {
  9002. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9003. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9004. }
  9005. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9006. {
  9007. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9008. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9009. }
  9010. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9011. {
  9012. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9013. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9014. }
  9015. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9016. {
  9017. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9018. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9019. }
  9020. }
  9021. json_object_put(tmpProfilee);
  9022. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9023. {
  9024. //------- not write to fptr2-------//
  9025. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9026. //clearflag = TRUE;
  9027. }
  9028. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9029. {
  9030. //------- not write to fptr2-------//
  9031. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9032. }
  9033. else if(stackLevelIsNULL == TRUE)
  9034. {
  9035. //Clear Whole File
  9036. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9037. clearflag = TRUE;
  9038. break;
  9039. }
  9040. else
  9041. {
  9042. fprintf(fptr2, sLineWord);//writing data into file
  9043. }
  9044. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9045. }
  9046. if(clearflag == TRUE)
  9047. {
  9048. fclose(fptr1);
  9049. fclose(fptr2);
  9050. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9051. system(str);
  9052. // clear temp file
  9053. sprintf(str,"rm -f %s",temp);
  9054. system(str);
  9055. }
  9056. else
  9057. {
  9058. fclose(fptr1);
  9059. fclose(fptr2);
  9060. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9061. system(str);
  9062. resultRename = rename(temp, chargingProfiles[k]);
  9063. if(resultRename == 0)
  9064. {
  9065. DEBUG_INFO("File ChargingProfile renamed successfully");
  9066. }
  9067. else
  9068. {
  9069. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9070. }
  9071. if(comfirmstr[0]== 0)
  9072. {
  9073. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9074. }
  9075. //Check chargingProfile is empty file
  9076. /*------ Read the file ----------------*/
  9077. fptr1=fopen(chargingProfiles[k],"r");
  9078. ch=fgetc(fptr1);
  9079. rewind(fptr1);
  9080. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9081. if(ch!=EOF)
  9082. {
  9083. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9084. {
  9085. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9086. if(sLineWord[0]=='\0')
  9087. {
  9088. isEmptyFile = TRUE;
  9089. break;
  9090. }
  9091. else
  9092. {
  9093. isEmptyFile = FALSE;
  9094. break;
  9095. }
  9096. }
  9097. }
  9098. else
  9099. isEmptyFile = TRUE;
  9100. fclose(fptr1);
  9101. if(isEmptyFile == TRUE)
  9102. {
  9103. memset(str, 0, ARRAY_SIZE(str));
  9104. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9105. system(str);
  9106. }
  9107. /*------- End of reading ---------------*/
  9108. }
  9109. } // while(int k=0; k < ChargeProfileCount; k++)
  9110. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9111. end:
  9112. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9113. {
  9114. if(connectorIdInt == 0)
  9115. {
  9116. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9117. {
  9118. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  9119. }
  9120. }
  9121. else
  9122. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  9123. }
  9124. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9125. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9126. return result;
  9127. }
  9128. void createFirmwareVersionByDataTransfer(void)
  9129. {
  9130. json_object *FirmwareDataTransfer = json_object_new_object();
  9131. // AC & DC model
  9132. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9133. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9134. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9135. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9136. // DC model
  9137. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9138. {
  9139. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9140. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9141. (gunType[3] != GUN_TYPE_UNKNOWN))
  9142. {
  9143. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9144. }
  9145. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9146. {
  9147. // DS DM DW
  9148. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9149. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9150. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9151. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9152. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9153. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9154. }
  9155. else
  9156. {
  9157. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9158. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9159. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9160. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9161. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9162. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9163. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9164. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9165. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9166. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9167. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9168. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9169. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9170. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9171. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9172. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9173. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9174. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9175. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9176. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9177. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9178. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9179. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9180. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9181. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9182. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9183. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9184. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9185. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9186. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9187. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9188. }
  9189. }
  9190. // 4G model
  9191. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9192. {
  9193. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9194. }
  9195. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9196. json_object_put(FirmwareDataTransfer);
  9197. }
  9198. int handleDataTransferRequest(char *uuid, char *payload)
  9199. {
  9200. mtrace();
  9201. json_object *response = json_object_new_object();
  9202. int result = FAIL;
  9203. char tempvendorId[255]={0};
  9204. char tempmessageId[50]={0};
  9205. char tempdata[1024]={0};
  9206. char message[2048]={0};
  9207. DEBUG_INFO("handleDataTransferRequest...\n");
  9208. if((uuid != NULL) && (payload != NULL))
  9209. {
  9210. json_object *DataTransfer;
  9211. DataTransfer = json_tokener_parse(payload);
  9212. if(!is_error(DataTransfer))
  9213. {
  9214. // Required data
  9215. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9216. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9217. // Optional data
  9218. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9219. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9220. if(json_object_object_get(DataTransfer, "data") != NULL)
  9221. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9222. result = PASS;
  9223. }
  9224. json_object_put(DataTransfer);
  9225. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9226. {
  9227. // Send all moudle firmware version on EVSE
  9228. createFirmwareVersionByDataTransfer();
  9229. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9230. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9231. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9232. json_object_put(response);
  9233. }
  9234. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9235. {
  9236. system("/usr/bin/run_tmate_restart.sh &");
  9237. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9238. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9239. json_object_put(response);
  9240. }
  9241. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9242. {
  9243. json_object *data;
  9244. data = json_tokener_parse(tempdata);
  9245. if(!is_error(data))
  9246. {
  9247. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9248. {
  9249. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9250. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9251. if(json_object_object_get(data, "SOC") != NULL)
  9252. {
  9253. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9254. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9255. }
  9256. if(json_object_object_get(data, "Energy") != NULL)
  9257. {
  9258. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9259. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9260. }
  9261. if(json_object_object_get(data, "Duration") != NULL)
  9262. {
  9263. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9264. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9265. }
  9266. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9267. }
  9268. else
  9269. {
  9270. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9271. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9272. }
  9273. }
  9274. else
  9275. {
  9276. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9277. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9278. }
  9279. json_object_put(data);
  9280. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9281. json_object_put(response);
  9282. }
  9283. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9284. {
  9285. json_object *data;
  9286. data = json_tokener_parse(tempdata);
  9287. if(!is_error(data))
  9288. {
  9289. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9290. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9291. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9292. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9293. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9294. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9295. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9296. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9297. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9298. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9299. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9300. }
  9301. else
  9302. {
  9303. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9304. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9305. }
  9306. json_object_put(data);
  9307. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9308. json_object_put(response);
  9309. }
  9310. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9311. {
  9312. json_object *data;
  9313. data = json_tokener_parse(tempdata);
  9314. if(!is_error(data))
  9315. {
  9316. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9317. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9318. if(json_object_object_get(data, "idToken") != NULL)
  9319. {
  9320. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9321. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9322. }
  9323. else
  9324. {
  9325. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9326. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9327. }
  9328. if(json_object_object_get(data, "price") != NULL) //v1.0
  9329. {
  9330. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9331. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9332. }
  9333. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9334. {
  9335. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9336. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9337. }
  9338. else
  9339. {
  9340. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9341. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9342. }
  9343. }
  9344. else
  9345. {
  9346. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9347. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9348. }
  9349. json_object_put(data);
  9350. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9351. json_object_put(response);
  9352. }
  9353. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9354. {
  9355. json_object *data;
  9356. data = json_tokener_parse(tempdata);
  9357. if(!is_error(data))
  9358. {
  9359. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9360. if(json_object_object_get(data, "txId") != NULL)
  9361. {
  9362. // California pricing V1.0
  9363. DEBUG_INFO("California pricing V1.0\n");
  9364. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9365. sprintf((char*)dmsVersion, "1.0");
  9366. for(int idx = 0;idx<gunTotalNumber;idx++)
  9367. {
  9368. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9369. {
  9370. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9371. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9372. if(json_object_object_get(data, "description") != NULL)
  9373. {
  9374. // California pricing V1.0
  9375. DEBUG_INFO("California pricing V1.0\n");
  9376. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9377. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9378. }
  9379. }
  9380. }
  9381. }
  9382. else if(json_object_object_get(data, "transactionId") != NULL)
  9383. {
  9384. // California pricing V2.0
  9385. DEBUG_INFO("California pricing V2.0\n");
  9386. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9387. sprintf((char*)dmsVersion, "2.0");
  9388. for(int idx=0;idx<gunTotalNumber;idx++)
  9389. {
  9390. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9391. {
  9392. if(json_object_object_get(data, "timestamp") != NULL)
  9393. {
  9394. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9395. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9396. }
  9397. else
  9398. {
  9399. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9400. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9401. }
  9402. if(json_object_object_get(data, "meterValue") != NULL)
  9403. {
  9404. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9405. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9406. }
  9407. else
  9408. {
  9409. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9410. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9411. }
  9412. if(json_object_object_get(data, "cost") != NULL)
  9413. {
  9414. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9415. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9416. }
  9417. else
  9418. {
  9419. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9420. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9421. }
  9422. if(json_object_object_get(data, "state") != NULL)
  9423. {
  9424. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9425. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9426. }
  9427. else
  9428. {
  9429. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9430. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9431. }
  9432. if(json_object_object_get(data, "chargingPrice") != NULL)
  9433. {
  9434. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9435. {
  9436. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9437. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9438. }
  9439. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9440. {
  9441. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9442. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9443. }
  9444. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9445. {
  9446. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9447. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9448. }
  9449. }
  9450. else
  9451. {
  9452. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9453. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9454. }
  9455. if(json_object_object_get(data, "idlePrice") != NULL)
  9456. {
  9457. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9458. {
  9459. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9460. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9461. }
  9462. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9463. {
  9464. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9465. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9466. }
  9467. }
  9468. if(json_object_object_get(data, "nextPeriod") != NULL)
  9469. {
  9470. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9471. {
  9472. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9473. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9474. }
  9475. else
  9476. {
  9477. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9478. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9479. }
  9480. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9481. {
  9482. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9483. {
  9484. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  9485. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  9486. }
  9487. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9488. {
  9489. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  9490. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  9491. }
  9492. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9493. {
  9494. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  9495. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  9496. }
  9497. }
  9498. else
  9499. {
  9500. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9501. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9502. }
  9503. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9504. {
  9505. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9506. {
  9507. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  9508. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  9509. }
  9510. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9511. {
  9512. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  9513. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  9514. }
  9515. }
  9516. }
  9517. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9518. {
  9519. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9520. {
  9521. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9522. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9523. }
  9524. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9525. {
  9526. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9527. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9528. }
  9529. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9530. {
  9531. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9532. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9533. }
  9534. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  9535. {
  9536. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9537. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9538. }
  9539. }
  9540. }
  9541. }
  9542. }
  9543. else
  9544. {
  9545. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9546. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9547. }
  9548. }
  9549. else
  9550. {
  9551. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9552. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9553. }
  9554. json_object_put(data);
  9555. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9556. json_object_put(response);
  9557. }
  9558. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9559. {
  9560. json_object *data;
  9561. data = json_tokener_parse(tempdata);
  9562. if(!is_error(data))
  9563. {
  9564. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9565. if(json_object_object_get(data, "txId") != NULL)
  9566. {
  9567. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9568. for(int idx = 0;idx<gunTotalNumber;idx++)
  9569. {
  9570. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9571. {
  9572. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9573. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9574. if(json_object_object_get(data, "description") != NULL)
  9575. {
  9576. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9577. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9578. }
  9579. else
  9580. {
  9581. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9582. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9583. }
  9584. }
  9585. }
  9586. }
  9587. else if(json_object_object_get(data, "transactionId") != NULL)
  9588. {
  9589. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9590. for(int idx = 0;idx<gunTotalNumber;idx++)
  9591. {
  9592. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9593. {
  9594. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9595. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9596. if(json_object_object_get(data, "cost") != NULL)
  9597. {
  9598. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  9599. ShmOCPP16DataPH->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9600. }
  9601. else
  9602. {
  9603. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9604. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9605. }
  9606. if(json_object_object_get(data, "priceText") != NULL)
  9607. {
  9608. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9609. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9610. }
  9611. else
  9612. {
  9613. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9614. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  9615. }
  9616. if(json_object_object_get(data, "qrCodeText") != NULL)
  9617. {
  9618. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9619. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9620. }
  9621. }
  9622. }
  9623. }
  9624. else
  9625. {
  9626. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9627. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9628. }
  9629. }
  9630. else
  9631. {
  9632. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9633. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9634. }
  9635. json_object_put(data);
  9636. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9637. json_object_put(response);
  9638. }
  9639. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9640. {
  9641. json_object *data;
  9642. data = json_tokener_parse(tempdata);
  9643. if(!is_error(data))
  9644. {
  9645. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9646. if(json_object_object_get(data, "Content_Type") != NULL)
  9647. {
  9648. if((0 <= json_object_get_int(json_object_object_get(data, "Content_Type"))) && (json_object_get_int(json_object_object_get(data, "Content_Type")) <= 1))
  9649. {
  9650. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9651. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9652. {
  9653. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9654. }
  9655. }
  9656. else
  9657. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9658. }
  9659. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9660. }
  9661. else
  9662. {
  9663. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9664. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9665. }
  9666. json_object_put(data);
  9667. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9668. json_object_put(response);
  9669. }
  9670. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9671. {
  9672. json_object *data;
  9673. data = json_tokener_parse(tempdata);
  9674. if(!is_error(data))
  9675. {
  9676. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9677. if(json_object_object_get(data, "ConnectorId") != NULL)
  9678. {
  9679. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9680. }
  9681. if(json_object_object_get(data, "SerialNo") != NULL)
  9682. {
  9683. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9684. }
  9685. if(json_object_object_get(data, "Page_Index") != NULL)
  9686. {
  9687. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9688. }
  9689. if(json_object_object_get(data, "Duration") != NULL)
  9690. {
  9691. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9692. }
  9693. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9694. }
  9695. else
  9696. {
  9697. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9698. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9699. }
  9700. json_object_put(data);
  9701. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9702. json_object_put(response);
  9703. }
  9704. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9705. {
  9706. json_object *data;
  9707. data = json_tokener_parse(tempdata);
  9708. if(!is_error(data))
  9709. {
  9710. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9711. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9712. {
  9713. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9714. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9715. else
  9716. {
  9717. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9718. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9719. }
  9720. }
  9721. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9722. {
  9723. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9724. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9725. else
  9726. {
  9727. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9728. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9729. }
  9730. }
  9731. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9732. {
  9733. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9734. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9735. else
  9736. {
  9737. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9738. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9739. }
  9740. }
  9741. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9742. {
  9743. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9744. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9745. else
  9746. {
  9747. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9748. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9749. }
  9750. }
  9751. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9752. {
  9753. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9754. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9755. else
  9756. {
  9757. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9758. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9759. }
  9760. }
  9761. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9762. {
  9763. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9764. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9765. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9766. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9767. else
  9768. {
  9769. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9770. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9771. }
  9772. }
  9773. if(json_object_object_get(data, "isAuthentication") != NULL)
  9774. {
  9775. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9776. {
  9777. case 0:
  9778. case 1:
  9779. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9780. break;
  9781. default:
  9782. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9783. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9784. break;
  9785. }
  9786. }
  9787. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9788. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9789. }
  9790. else
  9791. {
  9792. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9793. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9794. }
  9795. json_object_put(data);
  9796. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9797. json_object_put(response);
  9798. }
  9799. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9800. {
  9801. json_object *data;
  9802. data = json_tokener_parse(tempdata);
  9803. if(!is_error(data))
  9804. {
  9805. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9806. if(json_object_object_get(data, "stationName") != NULL)
  9807. {
  9808. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9809. }
  9810. else
  9811. {
  9812. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9813. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9814. }
  9815. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9816. {
  9817. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9818. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9819. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9820. }
  9821. }
  9822. else
  9823. {
  9824. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9825. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9826. }
  9827. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9828. json_object_put(response);
  9829. }
  9830. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9831. {
  9832. json_object *data;
  9833. data = json_tokener_parse(tempdata);
  9834. if(!is_error(data))
  9835. {
  9836. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9837. if(json_object_object_get(data, "weatherId") != NULL)
  9838. {
  9839. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9840. }
  9841. else
  9842. {
  9843. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9844. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9845. }
  9846. if(json_object_object_get(data, "Temperature") != NULL)
  9847. {
  9848. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9849. }
  9850. else
  9851. {
  9852. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9853. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9854. }
  9855. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9856. {
  9857. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9858. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9859. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9860. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9861. }
  9862. }
  9863. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9864. {
  9865. json_object *data;
  9866. data = json_tokener_parse(tempdata);
  9867. if(!is_error(data))
  9868. {
  9869. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9870. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9871. {
  9872. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9873. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9874. }
  9875. else
  9876. {
  9877. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9878. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9879. }
  9880. }
  9881. else
  9882. {
  9883. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9884. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9885. }
  9886. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9887. json_object_put(response);
  9888. }
  9889. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9890. {
  9891. json_object *data;
  9892. data = json_tokener_parse(tempdata);
  9893. if(!is_error(data))
  9894. {
  9895. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9896. {
  9897. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9898. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9899. if(gun_index < gunTotalNumber)
  9900. {
  9901. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9902. {
  9903. json_object *responsedata = json_object_new_object();
  9904. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9905. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9906. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9907. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9908. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9909. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9910. }
  9911. else
  9912. {
  9913. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9914. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9915. }
  9916. }
  9917. else
  9918. {
  9919. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9920. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9921. }
  9922. }
  9923. else
  9924. {
  9925. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9926. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9927. }
  9928. }
  9929. else
  9930. {
  9931. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9932. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9933. }
  9934. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9935. json_object_put(response);
  9936. }
  9937. else
  9938. {
  9939. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9940. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9941. }
  9942. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9943. json_object_put(response);
  9944. }
  9945. else
  9946. {
  9947. // Can not find valid message id
  9948. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9949. }
  9950. }
  9951. else
  9952. {
  9953. // Payload is null
  9954. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9955. }
  9956. LWS_Send(message);
  9957. return result;
  9958. }
  9959. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9960. {
  9961. mtrace();
  9962. int result = FAIL;
  9963. int connectorIdInt, durationInt;
  9964. char chargingRateUnitStr[4]={0};
  9965. char comfirmstr[20];
  9966. int confirmPeriods = 0;
  9967. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9968. json_object *GetCompositeSchedule;
  9969. GetCompositeSchedule = json_tokener_parse(payload);
  9970. if(!is_error(GetCompositeSchedule))
  9971. {
  9972. // Required data
  9973. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9974. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9975. else
  9976. connectorIdInt = -1;
  9977. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9978. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9979. else
  9980. durationInt = 86400;
  9981. // Optional data
  9982. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9983. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9984. }
  9985. json_object_put(GetCompositeSchedule);
  9986. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9987. if((connectorIdInt == 0) ||
  9988. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9989. {
  9990. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9991. struct StructChargingProfile tmpProfile[1];
  9992. if(strstr(chargingRateUnitStr, "W") != NULL)
  9993. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9994. else
  9995. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9996. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9997. {
  9998. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9999. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10000. }
  10001. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10002. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10003. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10004. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10005. {
  10006. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10007. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10008. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10009. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10010. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10011. {
  10012. confirmPeriods = idx;
  10013. break;
  10014. }
  10015. }
  10016. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10017. {
  10018. confirmPeriods += 1;
  10019. }
  10020. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10021. }
  10022. else
  10023. {
  10024. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10025. }
  10026. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10027. return result;
  10028. }
  10029. int handleGetConfigurationRequest(char *uuid, char *payload)
  10030. {
  10031. mtrace();
  10032. int result = FAIL;
  10033. int MaxKeySupported = 0;
  10034. int n_keys = 0;
  10035. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10036. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10037. json_object *GetConfiguration;
  10038. GetConfiguration = json_tokener_parse(payload);
  10039. if(!is_error(GetConfiguration))
  10040. {
  10041. // Optional data
  10042. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10043. {
  10044. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10045. {
  10046. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10047. n_keys = idx + 1;
  10048. }
  10049. }
  10050. }
  10051. json_object_put(GetConfiguration);
  10052. UnknownKeynum = 0;
  10053. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10054. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10055. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10056. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10057. if(n_keys != 0)
  10058. {
  10059. for(int i=0;i<n_keys;i++)
  10060. {
  10061. getKeyValue(requestKey[i]);
  10062. }
  10063. }
  10064. else
  10065. {
  10066. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10067. getKeyValue("");
  10068. }
  10069. processUnkownKey();
  10070. sendGetConfigurationConfirmation(uuid);
  10071. return result;
  10072. }
  10073. static char fnamePlusPath[100]={0};
  10074. static char fnamePWithNoPath[60]={0};
  10075. void checkUploadLog(void)
  10076. {
  10077. FILE *fp;
  10078. /* Open the command for reading. */
  10079. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10080. if (fp == NULL) {
  10081. DEBUG_WARN("Failed to run command\n" );
  10082. exit(1);
  10083. }
  10084. int ftppathlen = 0;
  10085. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10086. int i = 0;
  10087. /* Read the output a line at a time - output it. */
  10088. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10089. if(i==0)
  10090. {
  10091. ftppathlen = strlen(fnamePlusPath);
  10092. DEBUG_INFO("%s\n", fnamePlusPath);
  10093. fnamePlusPath[ftppathlen]='\0';
  10094. break;
  10095. }
  10096. i= i+1;
  10097. }
  10098. /* close */
  10099. pclose(fp);
  10100. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10101. {
  10102. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10103. {
  10104. fnamePlusPath[k]='\0';
  10105. }
  10106. }
  10107. i=1;
  10108. //char fname[60]={0};
  10109. while(i < ftppathlen)
  10110. {
  10111. int len=ftppathlen-i;
  10112. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10113. {
  10114. DEBUG_INFO("compare '/' all right\n");
  10115. break;
  10116. }
  10117. i=i+1;
  10118. }
  10119. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10120. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10121. fnamePWithNoPath[i+1] = '\0';
  10122. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10123. {
  10124. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10125. {
  10126. fnamePWithNoPath[j]='\0';
  10127. }
  10128. }
  10129. FILE* fp1 = fopen(fnamePlusPath, "r");
  10130. if (fp1)
  10131. {
  10132. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10133. // file exists
  10134. fclose(fp1);
  10135. }
  10136. else
  10137. {
  10138. // file doesn't exist
  10139. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10140. }
  10141. }
  10142. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10143. {
  10144. mtrace();
  10145. int result = FAIL;
  10146. time_t CurrentTime;
  10147. struct tm *tm;
  10148. pthread_t th_Status;
  10149. CurrentTime = time(NULL);
  10150. tm = localtime(&CurrentTime);
  10151. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  10152. sprintf((char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, "%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  10153. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10154. if(!interLock.isGetDiagnosticGoing)
  10155. {
  10156. interLock.isGetDiagnosticGoing = 1;
  10157. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10158. sleep(1);
  10159. }
  10160. else
  10161. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10162. return result;
  10163. }
  10164. void* GetDiagnosticsProcess(void* data)
  10165. {
  10166. pthread_detach(pthread_self());
  10167. mtrace();
  10168. int retriesInt=0, retryIntervalInt=0;
  10169. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10170. char protocol[10]={0}, user[64]={0},password[128]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  10171. int port=0;
  10172. int isSuccess = FALSE;
  10173. char ftpbuf[200]={0};
  10174. char cmdBuf[2048];
  10175. struct tm *tmNow;
  10176. time_t CurrentTime;
  10177. struct tm tmStart;
  10178. struct tm tmStop;
  10179. CurrentTime = time(NULL);
  10180. tmNow=localtime(&CurrentTime);
  10181. uint16_t targetYear, targetMonth;
  10182. json_object *GetDiagnostics;
  10183. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10184. GetDiagnostics = json_tokener_parse(data);
  10185. if(!is_error(GetDiagnostics))
  10186. {
  10187. // Required data
  10188. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10189. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10190. // Optional data
  10191. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10192. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10193. else
  10194. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10195. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10196. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10197. else
  10198. retryIntervalInt = 30;
  10199. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10200. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10201. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10202. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10203. }
  10204. json_object_put(GetDiagnostics);
  10205. // Pack log to compress file
  10206. if((sscanf((char*)startTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  10207. (sscanf((char*)stopTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  10208. {
  10209. // Pack system log
  10210. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10211. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10212. targetYear = tmStart.tm_year;
  10213. targetMonth = tmStart.tm_mon;
  10214. do
  10215. {
  10216. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10217. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10218. if(targetMonth+1>=13)
  10219. {
  10220. targetYear += 1;
  10221. targetMonth = 1;
  10222. }
  10223. else
  10224. {
  10225. targetMonth += 1;
  10226. }
  10227. }while((targetYear < (tmNow->tm_year+1900)) ||
  10228. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10229. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10230. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10231. system(cmdBuf);
  10232. // Pack charging & event log
  10233. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10234. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10235. targetYear = tmStart.tm_year;
  10236. targetMonth = tmStart.tm_mon;
  10237. do
  10238. {
  10239. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10240. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10241. if(targetMonth+1>=13)
  10242. {
  10243. targetYear += 1;
  10244. targetMonth = 1;
  10245. }
  10246. else
  10247. {
  10248. targetMonth += 1;
  10249. }
  10250. }while((targetYear < (tmNow->tm_year+1900)) ||
  10251. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10252. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10253. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10254. system(cmdBuf);
  10255. // Combine log file
  10256. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10257. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10258. }
  10259. else
  10260. {
  10261. system("exec /root/logPackTools 'log' 6");
  10262. }
  10263. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10264. system(cmdBuf);
  10265. checkUploadLog();
  10266. //****************location*******************/
  10267. if(strcmp(locationstr,"")==0)
  10268. {
  10269. DEBUG_INFO("location is <Empty>!\n");
  10270. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10271. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10272. goto end;
  10273. }
  10274. memset(protocol, 0, ARRAY_SIZE(protocol));
  10275. memset(user, 0, ARRAY_SIZE(user) );
  10276. memset(password, 0, ARRAY_SIZE(password));
  10277. memset(host, 0, ARRAY_SIZE(host));
  10278. memset(path, 0, ARRAY_SIZE(path));
  10279. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10280. memset(host1, 0, ARRAY_SIZE(host1));
  10281. memset(path1, 0, ARRAY_SIZE(path1));
  10282. /*location: ftp://user:password@host:port/path*/
  10283. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10284. if((access(fnamePlusPath,F_OK))!=-1)
  10285. {
  10286. DEBUG_INFO("fnamePlusPath exist.\n");
  10287. }
  10288. else
  10289. {
  10290. DEBUG_INFO("fnamePlusPath not exist!\n");
  10291. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10292. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10293. goto end;
  10294. }
  10295. if(strchr(locationstr,'@')==NULL)
  10296. {
  10297. sscanf(locationstr,
  10298. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10299. protocol, host, &port, path);
  10300. strcpy(user,"anonymous");
  10301. strcpy(password,"");
  10302. }
  10303. else
  10304. {
  10305. //DEBUG_INFO("pch=%s\n", pch);
  10306. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10307. protocol, user, password, host, &port, path);
  10308. }
  10309. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10310. {
  10311. DEBUG_INFO("protocol is not ftp/http ! \n");
  10312. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10313. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10314. goto end;
  10315. }
  10316. if(strncmp(locationstr,"http", 4) == 0)
  10317. {
  10318. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10319. sprintf(ftppath,"/%s", path);
  10320. do
  10321. {
  10322. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10323. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10324. sleep(3);
  10325. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10326. if(!isSuccess)
  10327. {
  10328. DEBUG_INFO("Diagnostics fail.\n");
  10329. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10330. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10331. sleep(retryIntervalInt);
  10332. }
  10333. else
  10334. {
  10335. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10336. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10337. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10338. }
  10339. retriesInt--;
  10340. }while((isSuccess == 0)&&(retriesInt >= 0));
  10341. }
  10342. else
  10343. {
  10344. sscanf(host,"%[^/]%s",host1, path1);
  10345. if(strlen(path) > 0)
  10346. sprintf(ftppath,"/%s", path);
  10347. else
  10348. sprintf(ftppath,"/%s", path1);
  10349. int ftppathlen=strlen(ftppath);
  10350. int i=1;
  10351. char filenametemp[50];
  10352. while(i < ftppathlen)
  10353. {
  10354. int len=ftppathlen-i;
  10355. if(ftppath[len]== 47) // '/' ascll code: 47
  10356. {
  10357. DEBUG_INFO("find '/' all right\n");
  10358. break;
  10359. }
  10360. i=i+1;
  10361. }
  10362. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10363. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10364. filenametemp[i+1] = 0;
  10365. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10366. if(port == 0)
  10367. port = 21;
  10368. do
  10369. {
  10370. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10371. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10372. sleep(3);
  10373. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10374. if(!isSuccess)
  10375. {
  10376. DEBUG_INFO("Diagnostics fail.\n");
  10377. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10378. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10379. sleep(retryIntervalInt);
  10380. }
  10381. else
  10382. {
  10383. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10384. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10385. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10386. }
  10387. retriesInt--;
  10388. }while((!isSuccess)&&(retriesInt >= 0));
  10389. }
  10390. end:
  10391. system("rm -f /mnt/*");
  10392. sleep(5);
  10393. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10394. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10395. interLock.isGetDiagnosticGoing = 0;
  10396. pthread_exit(NULL);
  10397. }
  10398. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10399. {
  10400. mtrace();
  10401. int result = FAIL;
  10402. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10403. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10404. {
  10405. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10406. locallistVersion = -1;
  10407. }
  10408. else
  10409. {
  10410. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10411. locallistVersion = 0;
  10412. OCPP_getListVerion();
  10413. }
  10414. //from db.OCPP_getListVerion
  10415. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10416. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10417. sendGetLocalListVersionConfirmation(uuid,"");
  10418. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10419. return result;
  10420. }
  10421. int handleRemoteStartRequest(char *uuid, char *payload)
  10422. {
  10423. mtrace();
  10424. int result = PASS;
  10425. int connectorIdInt=-1;
  10426. int tempIndex = 0;
  10427. char comfirmstr[20]={0};
  10428. char cmdBuf[512];
  10429. json_object *RemoteStartTransaction;
  10430. FILE *fp;
  10431. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10432. if(server_pending == TRUE)
  10433. {
  10434. result = FAIL;
  10435. }
  10436. RemoteStartTransaction = json_tokener_parse(payload);
  10437. if(!is_error(RemoteStartTransaction))
  10438. {
  10439. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10440. {
  10441. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10442. }
  10443. else
  10444. {
  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. connectorIdInt = (gun_index+1);
  10450. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10451. break;
  10452. }
  10453. }
  10454. }
  10455. if(connectorIdInt == 0)
  10456. {
  10457. DEBUG_WARN("Connector id shall not equal 0.\n");
  10458. result = FAIL;
  10459. }
  10460. else if(connectorIdInt == -1)
  10461. {
  10462. DEBUG_INFO("Connector id does not specific.\n");
  10463. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10464. {
  10465. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10466. // Required data
  10467. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10468. // Optional data
  10469. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10470. {
  10471. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10472. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10473. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10474. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10475. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10476. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10477. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10478. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10479. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10480. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10481. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10482. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10483. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10484. {
  10485. 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")));
  10486. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10487. 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"));
  10488. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10489. 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"));
  10490. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10491. 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")));
  10492. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10493. {
  10494. 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++)
  10495. {
  10496. 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"));
  10497. 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"));
  10498. 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)
  10499. 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"));
  10500. }
  10501. }
  10502. }
  10503. }
  10504. else
  10505. {
  10506. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10507. }
  10508. }
  10509. }
  10510. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10511. {
  10512. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10513. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10514. // Required data
  10515. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10516. // Optional data
  10517. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10518. {
  10519. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10520. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10521. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10522. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10523. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10524. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10525. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10526. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10527. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10528. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10529. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10530. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10531. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10532. {
  10533. 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")));
  10534. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10535. 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"));
  10536. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10537. 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"));
  10538. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10539. 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")));
  10540. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10541. {
  10542. 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++)
  10543. {
  10544. 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"));
  10545. 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"));
  10546. 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)
  10547. 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"));
  10548. }
  10549. }
  10550. }
  10551. }
  10552. else
  10553. {
  10554. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10555. }
  10556. }
  10557. else
  10558. {
  10559. DEBUG_WARN("Connector id is over maximun value.\n");
  10560. result = FAIL;
  10561. }
  10562. }
  10563. if(result == PASS)
  10564. {
  10565. if(connectorIdInt > 0)
  10566. {
  10567. //check Transaction active
  10568. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10569. {
  10570. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10571. {
  10572. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10573. }
  10574. else
  10575. {
  10576. tempIndex = connectorIdInt -1;
  10577. }
  10578. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10579. {
  10580. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10581. {
  10582. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10583. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10584. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10585. {
  10586. //Reserved
  10587. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10588. }
  10589. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10590. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10591. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10592. {
  10593. //Reserved
  10594. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10595. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10596. goto end;
  10597. }
  10598. else
  10599. {
  10600. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10601. {
  10602. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10603. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10604. goto end;
  10605. }
  10606. }//END FOR ELSE
  10607. }
  10608. }// END FOR CHAdeMO_QUANTITY
  10609. }
  10610. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10611. {
  10612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10613. {
  10614. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10615. }
  10616. else
  10617. {
  10618. tempIndex = connectorIdInt -1;
  10619. }
  10620. for (int index = 0; index < CCS_QUANTITY; index++)
  10621. {
  10622. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10623. {
  10624. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10625. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10626. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10627. {
  10628. //Reserved
  10629. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10630. }
  10631. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10632. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10633. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10634. {
  10635. //Reserved
  10636. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10637. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10638. goto end;
  10639. }
  10640. else
  10641. {
  10642. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10643. {
  10644. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10645. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10646. goto end;
  10647. }
  10648. }// END FOR ELSE
  10649. }
  10650. }// END FOR CCS_QUANTITY
  10651. }
  10652. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10653. {
  10654. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10655. {
  10656. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10657. }
  10658. else
  10659. {
  10660. tempIndex = connectorIdInt -1;
  10661. }
  10662. for (int index = 0; index < GB_QUANTITY; index++)
  10663. {
  10664. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10665. {
  10666. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10667. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10668. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10669. {
  10670. //Reserved
  10671. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10672. }
  10673. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10674. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10675. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10676. {
  10677. //Reserved
  10678. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10679. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10680. goto end;
  10681. }
  10682. else
  10683. {
  10684. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10685. {
  10686. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10687. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10688. goto end;
  10689. }
  10690. }// END FOR ELSE
  10691. }
  10692. } // END FOR GB_QUANTITY
  10693. }
  10694. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10695. {
  10696. tempIndex = connectorIdInt -1;
  10697. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10698. {
  10699. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10700. {
  10701. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10702. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10703. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10704. {
  10705. //Reserved
  10706. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10707. }
  10708. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10709. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10710. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10711. {
  10712. //Reserved
  10713. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10714. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10715. goto end;
  10716. }
  10717. else
  10718. {
  10719. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10720. {
  10721. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10722. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10723. goto end;
  10724. }
  10725. }// END FOR ELSE
  10726. }
  10727. } // END FOR GB_QUANTITY
  10728. }
  10729. else
  10730. {
  10731. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10732. {
  10733. tempIndex = 2;
  10734. }
  10735. else
  10736. {
  10737. tempIndex = connectorIdInt -1;
  10738. }
  10739. for (int index = 0; index < AC_QUANTITY; index++)
  10740. {
  10741. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10742. {
  10743. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10744. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10745. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10746. {
  10747. //Reserved
  10748. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10749. }
  10750. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10751. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10752. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10753. {
  10754. //Reserved
  10755. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10756. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10757. goto end;
  10758. }
  10759. else
  10760. {
  10761. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10762. {
  10763. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10764. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10765. goto end;
  10766. }
  10767. }//END FOR ELSE
  10768. }
  10769. }// END FOR AC_QUANTITY
  10770. }
  10771. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10772. {
  10773. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10774. {
  10775. // Save profile to file
  10776. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10777. system(cmdBuf);
  10778. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10779. fp = fopen(cmdBuf, "w");
  10780. 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));
  10781. fclose(fp);
  10782. }
  10783. else
  10784. {
  10785. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10786. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10787. goto end;
  10788. }
  10789. }
  10790. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10791. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10792. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10793. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10794. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10795. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10796. }
  10797. else
  10798. {
  10799. uint8_t isHasIdleConnector = FALSE;
  10800. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10801. {
  10802. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10803. {
  10804. isHasIdleConnector = TRUE;
  10805. break;
  10806. }
  10807. }
  10808. if((isHasIdleConnector == TRUE) && !ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10809. {
  10810. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10811. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10812. {
  10813. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10814. {
  10815. // Save profile to file
  10816. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10817. system(cmdBuf);
  10818. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10819. fp = fopen(cmdBuf, "w");
  10820. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10821. fclose(fp);
  10822. refreshStartTimer(&clientTime.RemoteStartWait);
  10823. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10824. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10825. }
  10826. else
  10827. {
  10828. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10829. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10830. }
  10831. }
  10832. else
  10833. {
  10834. refreshStartTimer(&clientTime.RemoteStartWait);
  10835. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10836. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10837. }
  10838. }
  10839. else
  10840. {
  10841. DEBUG_INFO("There is not any connector is idle.\n");
  10842. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10843. }
  10844. }
  10845. }
  10846. else
  10847. {
  10848. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10849. }
  10850. end:
  10851. json_object_put(RemoteStartTransaction);
  10852. sendRemoteStartConfirmation(uuid, comfirmstr);
  10853. return result;
  10854. }
  10855. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10856. {
  10857. mtrace();
  10858. int result = FAIL;
  10859. int match = FALSE;
  10860. int GunNO = 0;
  10861. int tempIndex = 0;
  10862. int transactionIdInt=0;
  10863. int transactionIdIsNULL= TRUE;
  10864. char comfirmstr[20];
  10865. json_object *RemoteStopTransaction;
  10866. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10867. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10868. if(server_pending == TRUE)
  10869. {
  10870. return 0;
  10871. }
  10872. RemoteStopTransaction = json_tokener_parse(payload);
  10873. if(!is_error(RemoteStopTransaction))
  10874. {
  10875. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10876. {
  10877. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10878. transactionIdIsNULL = FALSE;
  10879. }
  10880. }
  10881. json_object_put(RemoteStopTransaction);
  10882. if(transactionIdIsNULL == FALSE)
  10883. {
  10884. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10885. {
  10886. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10887. {
  10888. //check Transaction active
  10889. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10890. {
  10891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10892. {
  10893. tempIndex = ((gun_index==2) ? 1: 0);
  10894. }
  10895. else
  10896. {
  10897. tempIndex = gun_index;
  10898. }
  10899. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10900. {
  10901. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10902. {
  10903. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10904. {
  10905. match = TRUE;
  10906. GunNO = gun_index;
  10907. }
  10908. }
  10909. }// END FOR CHAdeMO_QUANTITY
  10910. }
  10911. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10912. {
  10913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10914. {
  10915. tempIndex = ((gun_index==2) ? 1: 0);
  10916. }
  10917. else
  10918. {
  10919. tempIndex = gun_index;
  10920. }
  10921. for (int index = 0; index < CCS_QUANTITY; index++)
  10922. {
  10923. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10924. {
  10925. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10926. {
  10927. match = TRUE;
  10928. GunNO = gun_index;
  10929. }
  10930. }
  10931. }// END FOR CCS_QUANTITY
  10932. }
  10933. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10934. {
  10935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10936. {
  10937. tempIndex = ((gun_index==2) ? 1: 0);
  10938. }
  10939. else
  10940. {
  10941. tempIndex = gun_index;
  10942. }
  10943. for (int index = 0; index < GB_QUANTITY; index++)
  10944. {
  10945. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10946. {
  10947. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10948. {
  10949. match = TRUE;
  10950. GunNO = gun_index;
  10951. }
  10952. }
  10953. }// END FOR GB_QUANTITY
  10954. }
  10955. else if(gunType[gun_index] == GUN_TYPE_DO)
  10956. {
  10957. tempIndex = gun_index;
  10958. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10959. {
  10960. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10961. {
  10962. 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
  10963. {
  10964. match = TRUE;
  10965. GunNO = gun_index;
  10966. }
  10967. }
  10968. }// END FOR GB_QUANTITY
  10969. }
  10970. else
  10971. {
  10972. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10973. {
  10974. tempIndex = 2;
  10975. }
  10976. else
  10977. {
  10978. tempIndex = gun_index;
  10979. }
  10980. for (int index = 0; index < AC_QUANTITY; index++)
  10981. {
  10982. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10983. {
  10984. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10985. {
  10986. match = TRUE;
  10987. GunNO = gun_index;
  10988. }
  10989. }
  10990. }// END FOR CHAdeMO_QUANTITY
  10991. } // END FOR AC ELSE
  10992. }// CHECK IF ResponseTransactionId == transactionIdInt
  10993. }//END FOR
  10994. if( match == TRUE)
  10995. {
  10996. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10997. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10998. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10999. }
  11000. else
  11001. {
  11002. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11003. }
  11004. }
  11005. else
  11006. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11007. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11008. return result;
  11009. }
  11010. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11011. {
  11012. mtrace();
  11013. int result = FAIL;
  11014. int connectorIdInt=0, reservationIdInt=0;
  11015. int tempIndex = 0;
  11016. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11017. char comfirmstr[20]={0};
  11018. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11019. int c = 0;
  11020. char *loc;
  11021. //char *ptr;
  11022. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11023. strcpy(sstrtemp, stringtrimspace(payload));
  11024. //***(1)connectorId ****/
  11025. c=0;
  11026. loc = strstr(sstrtemp, "connectorId");
  11027. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11028. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11029. {
  11030. sstr[c] = loc[strlen("connectorId")+2+c];
  11031. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11032. c++;
  11033. }
  11034. sstr[c] = '\0';
  11035. connectorIdInt = atoi(sstr);
  11036. //***(2)expiryDate ****/
  11037. loc = strstr(sstrtemp, "expiryDate");
  11038. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11039. c = 0;
  11040. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11041. {
  11042. sstr[c] = loc[3+strlen("expiryDate")+c];
  11043. c++;
  11044. }
  11045. sstr[c] = '\0';
  11046. strcpy(expiryDatestr, sstr);
  11047. //***(3)idTag ****/
  11048. loc = strstr(sstrtemp, "idTag");
  11049. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11050. c = 0;
  11051. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11052. {
  11053. sstr[c] = loc[3+strlen("idTag")+c];
  11054. c++;
  11055. }
  11056. sstr[c] = '\0';
  11057. strcpy(idTagstr, sstr);
  11058. //***(4)parentIdTag ****/
  11059. loc = strstr(sstrtemp, "parentIdTag");
  11060. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11061. c = 0;
  11062. if(loc == NULL)
  11063. {
  11064. strcpy(parentIdTagstr, "");
  11065. }
  11066. else
  11067. {
  11068. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11069. {
  11070. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11071. c++;
  11072. }
  11073. sstr[c] = '\0';
  11074. strcpy(parentIdTagstr, sstr);
  11075. }
  11076. //***(5)reservationId ****/
  11077. c=0;
  11078. loc = strstr(sstrtemp, "reservationId");
  11079. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11080. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11081. {
  11082. sstr[c] = loc[strlen("reservationId")+2+c];
  11083. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11084. c++;
  11085. }
  11086. sstr[c] = '\0';
  11087. reservationIdInt = atoi(sstr);
  11088. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11089. /*
  11090. enum SYSTEM_STATUS
  11091. {
  11092. SYS_MODE_BOOTING = 0,
  11093. SYS_MODE_IDLE = 1,
  11094. SYS_MODE_AUTHORIZING = 2,
  11095. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11096. SYS_MODE_REASSIGN = 4,
  11097. SYS_MODE_PREPARING = 5,
  11098. SYS_MODE_PREPARE_FOR_EV = 6,
  11099. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11100. SYS_MODE_CHARGING = 8,
  11101. SYS_MODE_TERMINATING = 9,
  11102. SYS_MODE_COMPLETE = 10,
  11103. SYS_MODE_ALARM = 11,
  11104. SYS_MODE_FAULT = 12,
  11105. SYS_MODE_RESERVATION = 13,
  11106. SYS_MODE_BOOKING = 14,
  11107. SYS_MODE_MAINTAIN = 15,
  11108. SYS_MODE_DEBUG = 16,
  11109. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11110. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11111. SYS_MODE_UPDATE = 19
  11112. };
  11113. */
  11114. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11115. {
  11116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11117. goto end;
  11118. }
  11119. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11120. {
  11121. //check Transaction active
  11122. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11123. {
  11124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11125. {
  11126. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11127. }
  11128. else
  11129. {
  11130. tempIndex = connectorIdInt -1;
  11131. }
  11132. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11133. {
  11134. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11135. {
  11136. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11137. {
  11138. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11139. {
  11140. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11141. {
  11142. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11143. {
  11144. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11145. }
  11146. else
  11147. {
  11148. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11149. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11150. }
  11151. }
  11152. 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'))
  11153. {
  11154. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11155. }
  11156. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11157. {
  11158. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11159. }
  11160. else
  11161. {
  11162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11163. }
  11164. }
  11165. 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
  11166. {
  11167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11168. }
  11169. }
  11170. else
  11171. {
  11172. //replace reservation
  11173. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11174. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11175. }
  11176. }
  11177. } // END FOR CHAdeMO_QUANTITY
  11178. }
  11179. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11180. {
  11181. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11182. {
  11183. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11184. }
  11185. else
  11186. {
  11187. tempIndex = connectorIdInt -1;
  11188. }
  11189. for (int index = 0; index < CCS_QUANTITY; index++)
  11190. {
  11191. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11192. {
  11193. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11194. {
  11195. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11196. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11197. {
  11198. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11199. {
  11200. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11201. {
  11202. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11203. }
  11204. else
  11205. {
  11206. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11207. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11208. }
  11209. }
  11210. 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'))
  11211. {
  11212. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11213. }
  11214. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11215. {
  11216. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11217. }
  11218. else
  11219. {
  11220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11221. }
  11222. }
  11223. 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
  11224. {
  11225. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11226. }
  11227. }
  11228. else
  11229. {
  11230. //replace reservation
  11231. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11232. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11233. }
  11234. }
  11235. } // END FOR CCS_QUANTITY
  11236. }
  11237. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11238. {
  11239. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11240. {
  11241. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11242. }
  11243. else
  11244. {
  11245. tempIndex = connectorIdInt -1;
  11246. }
  11247. for (int index = 0; index < GB_QUANTITY; index++)
  11248. {
  11249. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11250. {
  11251. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11252. {
  11253. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11254. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11255. {
  11256. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11257. {
  11258. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11259. {
  11260. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11261. }
  11262. else
  11263. {
  11264. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11265. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11266. }
  11267. }
  11268. 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'))
  11269. {
  11270. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11271. }
  11272. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11273. {
  11274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11275. }
  11276. else
  11277. {
  11278. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11279. }
  11280. }
  11281. else if((ShmSysConfigAndInfo->SysInfo.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
  11282. {
  11283. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11284. }
  11285. }
  11286. else
  11287. {
  11288. //replace reservation
  11289. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11290. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11291. }
  11292. }
  11293. }// END FOR GB_QUANTITY
  11294. }
  11295. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11296. {
  11297. tempIndex = connectorIdInt -1;
  11298. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11299. {
  11300. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11301. {
  11302. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11303. {
  11304. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11305. 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
  11306. {
  11307. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11308. {
  11309. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11310. {
  11311. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11312. }
  11313. else
  11314. {
  11315. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11316. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11317. }
  11318. }
  11319. 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'))
  11320. {
  11321. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11322. }
  11323. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11324. {
  11325. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11326. }
  11327. else
  11328. {
  11329. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11330. }
  11331. }
  11332. else if((ShmSysConfigAndInfo->SysInfo.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
  11333. {
  11334. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11335. }
  11336. }
  11337. else
  11338. {
  11339. //replace reservation
  11340. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11341. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11342. }
  11343. }
  11344. }// END FOR GB_QUANTITY
  11345. }
  11346. else
  11347. {
  11348. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11349. {
  11350. tempIndex = 2;
  11351. }
  11352. else
  11353. {
  11354. tempIndex = (connectorIdInt -1);
  11355. }
  11356. for (int index = 0; index < AC_QUANTITY; index++)
  11357. {
  11358. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11359. {
  11360. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11361. {
  11362. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11363. {
  11364. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11365. {
  11366. 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))
  11367. {
  11368. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11369. }
  11370. else
  11371. {
  11372. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11373. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11374. }
  11375. }
  11376. 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'))
  11377. {
  11378. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11379. }
  11380. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11381. {
  11382. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11383. }
  11384. else
  11385. {
  11386. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11387. }
  11388. }
  11389. 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
  11390. {
  11391. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11392. }
  11393. }
  11394. else
  11395. {
  11396. //replace reservation
  11397. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11398. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11399. }
  11400. }
  11401. } // END FOR AC_QUANTITY
  11402. }
  11403. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11404. }
  11405. else if(connectorIdInt == 0)
  11406. {
  11407. //check Transaction active
  11408. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11409. {
  11410. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11411. {
  11412. 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'))
  11413. {
  11414. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11415. goto end;
  11416. }
  11417. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11418. {
  11419. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11420. goto end;
  11421. }
  11422. 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
  11423. {
  11424. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11425. goto end;
  11426. }
  11427. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11428. {
  11429. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11430. goto end;
  11431. }
  11432. }
  11433. }// END FOR CHAdeMO_QUANTITY
  11434. for (int index = 0; index < CCS_QUANTITY; index++)
  11435. {
  11436. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11437. {
  11438. 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'))
  11439. {
  11440. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11441. goto end;
  11442. }
  11443. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11444. {
  11445. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11446. goto end;
  11447. }
  11448. 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
  11449. {
  11450. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11451. goto end;
  11452. }
  11453. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11454. {
  11455. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11456. goto end;
  11457. }
  11458. }
  11459. } // END FOR CCS_QUANTITY
  11460. for (int index = 0; index < GB_QUANTITY; index++)
  11461. {
  11462. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11463. {
  11464. 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'))
  11465. {
  11466. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11467. goto end;
  11468. }
  11469. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11470. {
  11471. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11472. goto end;
  11473. }
  11474. 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
  11475. {
  11476. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11477. goto end;
  11478. }
  11479. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11480. {
  11481. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11482. goto end;
  11483. }
  11484. }
  11485. } // END FOR GB_QUANTITY
  11486. for (int index = 0; index < AC_QUANTITY; index++)
  11487. {
  11488. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11489. {
  11490. 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'))
  11491. {
  11492. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11493. goto end;
  11494. }
  11495. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11496. {
  11497. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11498. goto end;
  11499. }
  11500. 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
  11501. {
  11502. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11503. goto end;
  11504. }
  11505. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11506. {
  11507. 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))
  11508. {
  11509. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11510. goto end;
  11511. }
  11512. }
  11513. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11514. {
  11515. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11516. goto end;
  11517. }
  11518. }
  11519. }// END FOR AC_QUANTITY
  11520. //The connectorId is 0
  11521. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11523. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11524. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11525. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11526. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11527. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11528. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11529. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11530. result = TRUE;
  11531. return result;
  11532. }
  11533. else
  11534. {
  11535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11536. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11537. }
  11538. if(strcmp(comfirmstr,"Accepted") == 0)
  11539. {
  11540. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11541. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11542. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11543. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11544. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11545. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11546. result = TRUE;
  11547. return result;
  11548. }
  11549. end:
  11550. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11551. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11552. return result;
  11553. }
  11554. int handleResetRequest(char *uuid, char *payload)
  11555. {
  11556. mtrace();
  11557. int result = FAIL;
  11558. char sstr[10]={0},sstrtemp[30]={ 0 };
  11559. char typestr[10]={0};
  11560. char comfirmstr[20]={0};
  11561. int c = 0;
  11562. char *loc;
  11563. DEBUG_INFO("handleResetRequest...\n");
  11564. strcpy(sstrtemp, stringtrimspace(payload));
  11565. loc = strstr(sstrtemp, "type");
  11566. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11567. c = 0;
  11568. while (loc[3+strlen("type")+c] != '\"')
  11569. {
  11570. sstr[c] = loc[3+strlen("type")+c];
  11571. c++;
  11572. }
  11573. sstr[c] = '\0';
  11574. strcpy(typestr,sstr);
  11575. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11576. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11577. {
  11578. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11579. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11580. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11581. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11582. }
  11583. else
  11584. {
  11585. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11586. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11587. result = PASS;
  11588. }
  11589. sendResetConfirmation(uuid, comfirmstr);
  11590. return result;
  11591. }
  11592. int handleSendLocalListRequest(char *uuid, char *payload)
  11593. {
  11594. mtrace();
  11595. int result = FAIL;
  11596. char comfirmstr[20];
  11597. int checkState_Faulted = FALSE;
  11598. json_object *SendLocalList;
  11599. DEBUG_INFO("handleSendLocalListRequest...\n");
  11600. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11601. {
  11602. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11603. goto end;
  11604. }
  11605. //check Charge Point state
  11606. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11607. {
  11608. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11609. {
  11610. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11611. }
  11612. }
  11613. for (int index = 0; index < CCS_QUANTITY; index++)
  11614. {
  11615. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11616. {
  11617. checkState_Faulted = TRUE; //OCPP Status
  11618. }
  11619. }
  11620. for (int index = 0; index < GB_QUANTITY; index++)
  11621. {
  11622. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11623. {
  11624. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11625. }
  11626. }
  11627. //check Charge Point state
  11628. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11629. {
  11630. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11631. {
  11632. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11633. }
  11634. }
  11635. //check Charge Point state
  11636. for (int index = 0; index < AC_QUANTITY; index++)
  11637. {
  11638. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11639. {
  11640. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11641. }
  11642. }
  11643. if(checkState_Faulted == TRUE)
  11644. {
  11645. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11646. goto end;
  11647. }
  11648. // Parsing payload
  11649. SendLocalList = json_tokener_parse(payload);
  11650. if(!is_error(SendLocalList))
  11651. {
  11652. // Required data
  11653. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11654. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11655. // Optional data
  11656. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11657. {
  11658. //Check UpdateType
  11659. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11660. {
  11661. //Local list full update
  11662. DEBUG_INFO("Local list full update.\n");
  11663. locallistVersion = 0;
  11664. OCPP_getListVerion();
  11665. /*if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11666. {
  11667. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11668. goto end;
  11669. }*/
  11670. OCPP_cleanLocalList();
  11671. }
  11672. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11673. {
  11674. //Local list different update
  11675. DEBUG_INFO("Local list different update.\n");
  11676. locallistVersion = 0;
  11677. OCPP_getListVerion();
  11678. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11679. {
  11680. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11681. goto end;
  11682. }
  11683. }
  11684. else
  11685. {
  11686. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11687. goto end;
  11688. }
  11689. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  11690. {
  11691. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  11692. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11693. goto end;
  11694. }
  11695. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11696. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11697. {
  11698. 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")));
  11699. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11700. {
  11701. 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")));
  11702. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11703. 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")));
  11704. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11705. 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")));
  11706. }
  11707. // Add to db
  11708. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11709. {
  11710. //Local list full update
  11711. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11712. idx,
  11713. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11714. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11715. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11716. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11717. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11718. // update list
  11719. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11720. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11721. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11722. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11723. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11724. }
  11725. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11726. {
  11727. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11728. idx,
  11729. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11730. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11731. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11732. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11733. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11734. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11735. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11736. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11737. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11738. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11739. }
  11740. }
  11741. }
  11742. else
  11743. {
  11744. //Check UpdateType
  11745. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11746. {
  11747. //Local list full update
  11748. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11749. OCPP_cleanLocalList();
  11750. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11751. goto end;
  11752. }
  11753. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11754. {
  11755. //Local list different update
  11756. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11757. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11758. goto end;
  11759. }
  11760. }
  11761. result = PASS;
  11762. }
  11763. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11764. end:
  11765. json_object_put(SendLocalList);
  11766. sendSendLocalListConfirmation(uuid, comfirmstr);
  11767. return result;
  11768. }
  11769. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11770. {
  11771. mtrace();
  11772. int result = FAIL;
  11773. struct StructSetChargingProfile SetProfileReq = {0};
  11774. int tempchargingProfileIdInt;
  11775. int tempstackLevelInt;
  11776. int chargingSchedulePeriodCount = 0;
  11777. char comfirmstr[20]={0};
  11778. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11779. char rmFileCmd[128]={0};
  11780. int profileQuantity = 0;
  11781. int replaceableProfileCnt = 0;
  11782. json_object *SetChargingProfile;
  11783. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11784. SetChargingProfile = json_tokener_parse(payload);
  11785. if(!is_error(SetChargingProfile))
  11786. {
  11787. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11788. {
  11789. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11790. }
  11791. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11792. {
  11793. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11794. {
  11795. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11796. }
  11797. else
  11798. {
  11799. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11800. DEBUG_WARN("Cannot find chargingProfileId field.");
  11801. goto end;
  11802. }
  11803. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11804. {
  11805. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11806. }
  11807. else
  11808. {
  11809. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11810. DEBUG_WARN("Cannot find stackLevel field.");
  11811. goto end;
  11812. }
  11813. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11814. {
  11815. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11816. }
  11817. else
  11818. {
  11819. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11820. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  11821. goto end;
  11822. }
  11823. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11824. {
  11825. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11826. }
  11827. else
  11828. {
  11829. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11830. DEBUG_WARN("Cannot find chargingProfileKind field.");
  11831. goto end;
  11832. }
  11833. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11834. {
  11835. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11836. }
  11837. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11838. {
  11839. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11840. }
  11841. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11842. {
  11843. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11844. }
  11845. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11846. {
  11847. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11848. }
  11849. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11850. {
  11851. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11852. {
  11853. 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")));
  11854. }
  11855. else
  11856. {
  11857. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11858. DEBUG_WARN("Cannot find chargingRateUnit field.");
  11859. goto end;
  11860. }
  11861. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11862. {
  11863. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11864. }
  11865. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11866. {
  11867. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11868. }
  11869. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11870. {
  11871. 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")));
  11872. }
  11873. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11874. {
  11875. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11876. if(chargingSchedulePeriodCount <= 10)
  11877. {
  11878. 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++)
  11879. {
  11880. 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)
  11881. {
  11882. 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"));
  11883. }
  11884. else
  11885. {
  11886. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11887. DEBUG_WARN("Cannot find startPeriod field.");
  11888. goto end;
  11889. }
  11890. 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)
  11891. {
  11892. 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"));
  11893. }
  11894. else
  11895. {
  11896. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11897. DEBUG_WARN("Cannot find limit field.");
  11898. goto end;
  11899. }
  11900. 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)
  11901. {
  11902. 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"));
  11903. }
  11904. }
  11905. }
  11906. }
  11907. else
  11908. {
  11909. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11910. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  11911. goto end;
  11912. }
  11913. }
  11914. else
  11915. {
  11916. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11917. DEBUG_WARN("Cannot find chargingSchedule field.");
  11918. goto end;
  11919. }
  11920. }
  11921. }
  11922. // Profile periods quantity check
  11923. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11924. {
  11925. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11926. goto end;
  11927. }
  11928. // Check invalid limit
  11929. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  11930. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  11931. {
  11932. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11933. {
  11934. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11935. {
  11936. 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)))) ||
  11937. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11938. {
  11939. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11940. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11941. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11942. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11943. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11944. goto end;
  11945. }
  11946. }
  11947. }
  11948. else
  11949. {
  11950. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11951. {
  11952. 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) ||
  11953. (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)))
  11954. {
  11955. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11956. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11957. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11958. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11959. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11960. goto end;
  11961. }
  11962. }
  11963. }
  11964. }
  11965. // Profile purpose info check
  11966. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11967. {
  11968. FILE *fp;
  11969. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11970. if(SetProfileReq.ConnectorId != 0)
  11971. {
  11972. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11973. goto end;
  11974. }
  11975. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11976. if (!fp)
  11977. {
  11978. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11979. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11980. }
  11981. else
  11982. {
  11983. char *line = NULL;
  11984. size_t len = 0;
  11985. while(getline(&line, &len, fp) != -1)
  11986. {
  11987. json_object *obj = NULL;
  11988. obj = json_tokener_parse(line);
  11989. if(is_error(obj))
  11990. {
  11991. DEBUG_ERROR("Parse txProfile from file error.\n");
  11992. }
  11993. else
  11994. {
  11995. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11996. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11997. {
  11998. profileQuantity += 1;
  11999. }
  12000. else
  12001. replaceableProfileCnt += 1;
  12002. }
  12003. }
  12004. }
  12005. fclose(fp);
  12006. }
  12007. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12008. {
  12009. FILE *fp;
  12010. char filename[128]={0};
  12011. int tmpProfileQuantity;
  12012. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12013. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12014. {
  12015. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12016. goto end;
  12017. }
  12018. if(SetProfileReq.ConnectorId == 0)
  12019. {
  12020. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12021. {
  12022. tmpProfileQuantity = 0;
  12023. memset(filename, 0, ARRAY_SIZE(filename));
  12024. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12025. fp = fopen(filename, "r");
  12026. if (!fp)
  12027. {
  12028. DEBUG_INFO("%s does not create.\n", filename);
  12029. fp = fopen(filename, "w+");
  12030. }
  12031. else
  12032. {
  12033. char *line = NULL;
  12034. size_t len = 0;
  12035. while(getline(&line, &len, fp) != -1)
  12036. {
  12037. json_object *obj = NULL;
  12038. obj = json_tokener_parse(line);
  12039. if(is_error(obj))
  12040. {
  12041. DEBUG_ERROR("Parse txProfile from file error.\n");
  12042. }
  12043. else
  12044. {
  12045. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12046. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12047. {
  12048. tmpProfileQuantity += 1;
  12049. }
  12050. else
  12051. replaceableProfileCnt += 1;
  12052. }
  12053. }
  12054. }
  12055. fclose(fp);
  12056. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12057. }
  12058. }
  12059. else
  12060. {
  12061. memset(filename, 0, ARRAY_SIZE(filename));
  12062. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12063. fp = fopen(filename, "r");
  12064. if (!fp)
  12065. {
  12066. DEBUG_INFO("%s does not create.\n", filename);
  12067. fp = fopen(filename, "w+");
  12068. }
  12069. else
  12070. {
  12071. char *line = NULL;
  12072. size_t len = 0;
  12073. while(getline(&line, &len, fp) != -1)
  12074. {
  12075. json_object *obj = NULL;
  12076. obj = json_tokener_parse(line);
  12077. if(is_error(obj))
  12078. {
  12079. DEBUG_ERROR("Parse txProfile from file error.\n");
  12080. }
  12081. else
  12082. {
  12083. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12084. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12085. {
  12086. profileQuantity += 1;
  12087. }
  12088. else
  12089. replaceableProfileCnt += 1;
  12090. }
  12091. }
  12092. }
  12093. fclose(fp);
  12094. }
  12095. }
  12096. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12097. {
  12098. int isMatchTransactiodId= FALSE;
  12099. FILE *fp;
  12100. char filename[128]={0};
  12101. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12102. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12103. if(SetProfileReq.ConnectorId == 0)
  12104. {
  12105. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12106. goto end;
  12107. }
  12108. int tempIndex = 0;
  12109. //check Transaction active
  12110. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12111. {
  12112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12113. {
  12114. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12115. }
  12116. else
  12117. {
  12118. tempIndex = SetProfileReq.ConnectorId -1;
  12119. }
  12120. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12121. {
  12122. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12123. {
  12124. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12125. {
  12126. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12127. {
  12128. isMatchTransactiodId = TRUE;
  12129. break;
  12130. }
  12131. }
  12132. }
  12133. }
  12134. }
  12135. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12136. {
  12137. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12138. {
  12139. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12140. }
  12141. else
  12142. {
  12143. tempIndex = SetProfileReq.ConnectorId -1;
  12144. }
  12145. for (int index = 0; index < CCS_QUANTITY; index++)
  12146. {
  12147. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12148. {
  12149. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12150. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12151. {
  12152. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12153. {
  12154. isMatchTransactiodId = TRUE;
  12155. break;
  12156. }
  12157. }
  12158. }
  12159. }
  12160. }
  12161. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12162. {
  12163. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12164. {
  12165. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12166. }
  12167. else
  12168. {
  12169. tempIndex = SetProfileReq.ConnectorId -1;
  12170. }
  12171. for (int index = 0; index < GB_QUANTITY; index++)
  12172. {
  12173. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12174. {
  12175. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12176. {
  12177. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12178. {
  12179. isMatchTransactiodId = TRUE;
  12180. break;
  12181. }
  12182. }
  12183. }
  12184. }
  12185. }
  12186. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12187. {
  12188. tempIndex = SetProfileReq.ConnectorId -1;
  12189. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12190. {
  12191. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12192. {
  12193. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12194. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12195. {
  12196. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12197. {
  12198. isMatchTransactiodId = TRUE;
  12199. break;
  12200. }
  12201. }
  12202. }
  12203. }
  12204. }
  12205. else
  12206. {
  12207. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12208. {
  12209. tempIndex = 2;
  12210. }
  12211. else
  12212. {
  12213. tempIndex = (SetProfileReq.ConnectorId -1);
  12214. }
  12215. for (int index = 0; index < AC_QUANTITY; index++)
  12216. {
  12217. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12218. {
  12219. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12220. {
  12221. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12222. {
  12223. isMatchTransactiodId = TRUE;
  12224. break;
  12225. }
  12226. }
  12227. }
  12228. }
  12229. }
  12230. //check Transaction active
  12231. if(isMatchTransactiodId == FALSE)
  12232. {
  12233. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12234. goto end;
  12235. }
  12236. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12237. {
  12238. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12239. goto end;
  12240. }
  12241. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12242. fp = fopen(filename, "r");
  12243. if (!fp)
  12244. {
  12245. DEBUG_INFO("%s does not create.\n", filename);
  12246. fp = fopen(filename, "w+");
  12247. }
  12248. else
  12249. {
  12250. char *line = NULL;
  12251. size_t len = 0;
  12252. while(getline(&line, &len, fp) != -1)
  12253. {
  12254. json_object *obj = NULL;
  12255. obj = json_tokener_parse(line);
  12256. if(is_error(obj))
  12257. {
  12258. DEBUG_ERROR("Parse txProfile from file error.\n");
  12259. }
  12260. else
  12261. {
  12262. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12263. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12264. {
  12265. profileQuantity += 1;
  12266. }
  12267. else
  12268. replaceableProfileCnt += 1;
  12269. }
  12270. }
  12271. }
  12272. fclose(fp);
  12273. }
  12274. // Check ChargeProfileMaxStackLevel
  12275. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12276. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12277. {
  12278. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12279. goto end;
  12280. }
  12281. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12282. {
  12283. FILE *fp;
  12284. char dataLine[4096]={0};
  12285. char fnametemp[128]={0};
  12286. int tmpProfileQuantity;
  12287. //Check ChargePointMaxProfile.json exit
  12288. profileQuantity = 0;
  12289. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12290. {
  12291. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12292. //Check Charging Profile Count
  12293. tmpProfileQuantity = 0;
  12294. while(fscanf(fp, "%s", dataLine) != EOF)
  12295. {
  12296. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12297. {
  12298. profileQuantity += 1;
  12299. tmpProfileQuantity += 1;
  12300. }
  12301. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12302. }
  12303. fclose(fp);
  12304. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12305. }
  12306. //Check TxDefaultProfile_%d.json
  12307. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12308. {
  12309. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12310. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12311. if((access(fnametemp,F_OK))!=-1)
  12312. {
  12313. fp = fopen(fnametemp, "r");
  12314. //Check Charging Profile Count
  12315. tmpProfileQuantity = 0;
  12316. while(fscanf(fp, "%s", dataLine) != EOF)
  12317. {
  12318. //DEBUG_INFO("word=%s\n",word);
  12319. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12320. {
  12321. profileQuantity += 1;
  12322. tmpProfileQuantity += 1;
  12323. }
  12324. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12325. }
  12326. fclose(fp);
  12327. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12328. }
  12329. }
  12330. //Check TxProfile_%d.json
  12331. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12332. {
  12333. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12334. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12335. if((access(fnametemp,F_OK))!=-1)
  12336. {
  12337. fp = fopen(fnametemp, "r");
  12338. //Check Charging Profile Count
  12339. tmpProfileQuantity = 0;
  12340. while(fscanf(fp, "%s", dataLine) != EOF)
  12341. {
  12342. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12343. {
  12344. profileQuantity += 1;
  12345. tmpProfileQuantity += 1;
  12346. }
  12347. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12348. }
  12349. fclose(fp);
  12350. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12351. }
  12352. }
  12353. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12354. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12355. // To check total Profile quantity
  12356. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12357. {
  12358. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12359. {
  12360. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12361. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12362. goto end;
  12363. }
  12364. }
  12365. else
  12366. {
  12367. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12368. {
  12369. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12370. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12371. goto end;
  12372. }
  12373. }
  12374. }
  12375. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12376. //**********************************Write to File********************************************************/
  12377. {
  12378. FILE *infile;
  12379. FILE *outfile;
  12380. char dataLine[4096]={0};
  12381. char filename[128]={0};
  12382. int chkChar=0;
  12383. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12384. {
  12385. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12386. {
  12387. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12388. }
  12389. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12390. {
  12391. if(SetProfileReq.ConnectorId==0)
  12392. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12393. else
  12394. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12395. }
  12396. else
  12397. {
  12398. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12399. }
  12400. infile = fopen (filename, "r");
  12401. outfile = fopen (tempfile, "w");
  12402. chkChar = fgetc(infile);
  12403. rewind(infile);
  12404. if(chkChar == EOF)
  12405. {
  12406. // Profile is empty
  12407. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12408. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12409. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12410. fclose(infile);
  12411. fclose(outfile);
  12412. sprintf(rmFileCmd,"rm -f %s",filename);
  12413. system(rmFileCmd);
  12414. rename(tempfile, filename);
  12415. }
  12416. else
  12417. {
  12418. // Profile is not empty
  12419. int ChargingProfileAdded = FALSE;
  12420. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12421. {
  12422. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12423. json_object *tmpChargingProfile;
  12424. tmpChargingProfile = json_tokener_parse(dataLine);
  12425. if(!is_error(SetChargingProfile))
  12426. {
  12427. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12428. {
  12429. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12430. {
  12431. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12432. }
  12433. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12434. {
  12435. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12436. }
  12437. }
  12438. }
  12439. json_object_put(tmpChargingProfile);
  12440. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12441. {
  12442. if(ChargingProfileAdded == FALSE)
  12443. {
  12444. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12445. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12446. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12447. ChargingProfileAdded = TRUE;
  12448. }
  12449. }
  12450. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12451. {
  12452. if(ChargingProfileAdded == FALSE)
  12453. {
  12454. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12455. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12456. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12457. ChargingProfileAdded = TRUE;
  12458. }
  12459. }
  12460. else
  12461. {
  12462. fprintf(outfile,"%s\n",dataLine);
  12463. if(ChargingProfileAdded == FALSE)
  12464. {
  12465. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12466. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12467. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12468. ChargingProfileAdded = TRUE;
  12469. }
  12470. }
  12471. } // end of while loop
  12472. fclose(infile);
  12473. fclose(outfile);
  12474. sprintf(rmFileCmd,"rm -f %s",filename);
  12475. system(rmFileCmd);
  12476. rename(tempfile, filename);
  12477. }
  12478. }
  12479. sleep(1);
  12480. result = TRUE;
  12481. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12482. }
  12483. end:
  12484. json_object_put(SetChargingProfile);
  12485. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12486. {
  12487. if(SetProfileReq.ConnectorId == 0)
  12488. {
  12489. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12490. {
  12491. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12492. }
  12493. }
  12494. else
  12495. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12496. }
  12497. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12498. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12499. return result;
  12500. }
  12501. int handleTriggerMessageRequest(char *uuid, char *payload)
  12502. {
  12503. mtrace();
  12504. int result = FAIL;
  12505. int connectorIdIsNULL = FALSE;
  12506. int connectorIdInt =0;
  12507. char sstr[40]={0},sstrtemp[100]={ 0 };
  12508. char requestedMessagestr[40]={0};
  12509. char comfirmstr[20]={0};
  12510. int c = 0;
  12511. char *loc;
  12512. DEBUG_INFO("handleTriggerMessageRequest\n");
  12513. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12514. strcpy(sstrtemp, stringtrimspace(payload));
  12515. c = 0;
  12516. loc = strstr(sstrtemp, "requestedMessage");
  12517. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12518. {
  12519. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12520. c++;
  12521. }
  12522. sstr[c] = '\0';
  12523. strcpy(requestedMessagestr, sstr);
  12524. c = 0;
  12525. loc = strstr(sstrtemp, "connectorId");
  12526. if(loc == NULL)
  12527. {
  12528. connectorIdIsNULL = TRUE;
  12529. }
  12530. else
  12531. {
  12532. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12533. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12534. {
  12535. sstr[c] = loc[strlen("connectorId")+2+c];
  12536. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12537. c++;
  12538. }
  12539. sstr[c] = '\0';
  12540. connectorIdInt = atoi(sstr);
  12541. }
  12542. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12543. {
  12544. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12545. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12546. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12547. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12548. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12549. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12550. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12551. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12552. {
  12553. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12554. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12555. return TRUE;
  12556. }
  12557. else
  12558. {
  12559. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12560. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12561. }
  12562. }
  12563. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12564. {
  12565. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12566. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12567. return TRUE;
  12568. }
  12569. //==========================
  12570. // Trigger message
  12571. //==========================
  12572. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12573. {
  12574. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12575. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12576. {
  12577. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12578. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12579. }
  12580. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12581. }
  12582. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12583. {
  12584. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12585. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12586. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12587. }
  12588. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12589. {
  12590. //sendBootNotificationRequest();
  12591. server_sign = FALSE;
  12592. }
  12593. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12594. {
  12595. refreshStartTimer(&clientTime.Heartbeat);
  12596. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12597. }
  12598. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12599. {
  12600. if(connectorIdIsNULL == FALSE)
  12601. {
  12602. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12603. {
  12604. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12605. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12606. }
  12607. }
  12608. else
  12609. {
  12610. for(int idx=0;idx< gunTotalNumber;idx++)
  12611. {
  12612. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12613. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12614. }
  12615. }
  12616. }
  12617. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12618. {
  12619. if(connectorIdIsNULL == FALSE)
  12620. {
  12621. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12622. {
  12623. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12624. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12625. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12626. }
  12627. }
  12628. else
  12629. {
  12630. for(int idx=0;idx< gunTotalNumber;idx++)
  12631. {
  12632. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12633. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12634. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12635. }
  12636. }
  12637. }
  12638. return result;
  12639. }
  12640. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12641. {
  12642. mtrace();
  12643. int result = FAIL;
  12644. int connectorIdInt =0;
  12645. char comfirmstr[20]={0};
  12646. int tempIndex = 0;
  12647. json_object *UnlockConnector;
  12648. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12649. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12650. UnlockConnector = json_tokener_parse(payload);
  12651. if(!is_error(UnlockConnector))
  12652. {
  12653. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12654. {
  12655. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12656. }
  12657. }
  12658. json_object_put(UnlockConnector);
  12659. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12660. if(gunTotalNumber == 0)
  12661. {
  12662. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12663. goto end;
  12664. }
  12665. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12666. {
  12667. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12668. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12669. goto end;
  12670. }
  12671. else
  12672. {
  12673. //check Transaction active
  12674. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12675. {
  12676. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12677. {
  12678. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12679. }
  12680. else
  12681. {
  12682. tempIndex = connectorIdInt -1;
  12683. }
  12684. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12685. {
  12686. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12687. {
  12688. //stop Transaction
  12689. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12690. }
  12691. }
  12692. }
  12693. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12694. {
  12695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12696. {
  12697. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12698. }
  12699. else
  12700. {
  12701. tempIndex = connectorIdInt -1;
  12702. }
  12703. for (int index = 0; index < CCS_QUANTITY; index++)
  12704. {
  12705. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12706. {
  12707. //stop Transaction
  12708. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12709. }
  12710. }
  12711. }
  12712. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12713. {
  12714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12715. {
  12716. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12717. }
  12718. else
  12719. {
  12720. tempIndex = connectorIdInt -1;
  12721. }
  12722. for (int index = 0; index < GB_QUANTITY; index++)
  12723. {
  12724. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12725. {
  12726. //stop Transaction
  12727. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12728. }
  12729. }
  12730. }
  12731. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12732. {
  12733. tempIndex = connectorIdInt -1;
  12734. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12735. {
  12736. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12737. {
  12738. //stop Transaction
  12739. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12740. }
  12741. }
  12742. }
  12743. else
  12744. {
  12745. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12746. {
  12747. tempIndex = 2;
  12748. }
  12749. else
  12750. {
  12751. tempIndex = connectorIdInt-1;
  12752. }
  12753. for (int index = 0; index < AC_QUANTITY; index++)
  12754. {
  12755. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12756. {
  12757. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12758. }
  12759. }
  12760. }
  12761. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12762. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12763. result = TRUE;
  12764. return result;
  12765. }
  12766. end:
  12767. //json_object_put(obj); --- remove temporally
  12768. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12769. return result;
  12770. }
  12771. static char UpdateFirmwarepayloadData[300]={0};
  12772. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12773. {
  12774. mtrace();
  12775. int result = FAIL;
  12776. pthread_t t;
  12777. sendUpdateFirmwareConfirmation(uuid);
  12778. memset(UpdateFirmwarepayloadData, 0, 300);
  12779. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12780. if(!interLock.isUpdateFirmwareGoing)
  12781. {
  12782. interLock.isUpdateFirmwareGoing = 1;
  12783. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12784. sleep(1);
  12785. }
  12786. else
  12787. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12788. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12789. return result;
  12790. }
  12791. void *UpdateFirmwareProcess(void *data)
  12792. {
  12793. pthread_detach(pthread_self());
  12794. mtrace();
  12795. int retriesInt =0, retryIntervalInt=0;
  12796. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12797. int port=0;
  12798. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12799. int isSuccess = 0;
  12800. char ftpbuf[512];
  12801. char temp[100];
  12802. char * pch;
  12803. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12804. json_object *UpdateFirmware;
  12805. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12806. if(!is_error(UpdateFirmware))
  12807. {
  12808. // Required data
  12809. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12810. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12811. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12812. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12813. // Optional data
  12814. if(json_object_object_get(UpdateFirmware, "retries"))
  12815. {
  12816. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12817. }
  12818. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12819. {
  12820. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12821. }
  12822. }
  12823. json_object_put(UpdateFirmware);
  12824. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12825. memset(path, 0, ARRAY_SIZE(path));
  12826. // Wait retrieveData
  12827. if(strlen(retrieveDatestr) > 10)
  12828. {
  12829. do
  12830. {
  12831. sleep(1);
  12832. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12833. }
  12834. // Ready to download
  12835. system("rm -f /mnt/*");
  12836. if(strncmp(locationstr,"http", 4) == 0)
  12837. {
  12838. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12839. sprintf(ftppath,"/%s", path);
  12840. DEBUG_INFO("locationstr: %s\n", locationstr);
  12841. DEBUG_INFO("protocol: %s\n",protocol);
  12842. DEBUG_INFO("host: %s\n",host);
  12843. DEBUG_INFO("path: %s\n",path);
  12844. DEBUG_INFO("ftppath: %s\n",ftppath);
  12845. int ftppathlen=strlen(ftppath);
  12846. int i=1;
  12847. char filenametemp[50];
  12848. while(i < ftppathlen)
  12849. {
  12850. int len=ftppathlen-i;
  12851. if(ftppath[len]== 47) // '/' ascll code: 47
  12852. {
  12853. DEBUG_INFO("compare '/' all right\n");
  12854. break;
  12855. }
  12856. i=i+1;
  12857. }
  12858. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12859. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12860. filenametemp[i+1] = 0;
  12861. do
  12862. {
  12863. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12864. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12865. sleep(1);
  12866. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12867. if(!isSuccess)
  12868. {
  12869. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12870. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12871. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12872. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12873. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12874. }
  12875. else
  12876. {
  12877. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12878. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12879. }
  12880. retriesInt--;
  12881. }while((isSuccess == 0)&&(retriesInt >= 0));
  12882. }
  12883. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  12884. {
  12885. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12886. memset(temp, 0, ARRAY_SIZE(temp));
  12887. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12888. strcpy(ftpbuf, locationstr);
  12889. int ftppathlen=strlen(ftpbuf);
  12890. int i=1;
  12891. char filenametemp[50];
  12892. while(i < ftppathlen)
  12893. {
  12894. int len=ftppathlen-i;
  12895. if(ftpbuf[len]== 47) // '/' ascii code: 47
  12896. {
  12897. DEBUG_INFO(" compare '/' all right\n");
  12898. break;
  12899. }
  12900. i=i+1;
  12901. }
  12902. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12903. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12904. filenametemp[i+1] = 0;
  12905. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12906. pch=strchr(temp,'@');
  12907. if(pch==NULL)
  12908. {
  12909. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12910. protocol, host, &port, path);
  12911. strcpy(user,"anonymous");
  12912. strcpy(password,"");
  12913. }
  12914. else
  12915. {
  12916. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  12917. protocol, user, host, &port, path);
  12918. }
  12919. sscanf(host,"%[^/]%s",host1, path1);
  12920. sprintf(ftppath,"%s:/%s", host,path);
  12921. if(port == 0)
  12922. {
  12923. port = 21;
  12924. }
  12925. do
  12926. {
  12927. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12928. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12929. sleep(1);
  12930. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  12931. if(!isSuccess)
  12932. {
  12933. //BulldogUtil.sleepMs(interval*1000);
  12934. DEBUG_INFO("Update firmware request and download file fail.\n");
  12935. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12936. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12937. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12938. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12939. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12940. }
  12941. else
  12942. {
  12943. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12944. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12945. }
  12946. retriesInt--;
  12947. }while((!isSuccess)&&(retriesInt >= 0));
  12948. }
  12949. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12950. {
  12951. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12952. memset(temp, 0, ARRAY_SIZE(temp));
  12953. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12954. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12955. int ftppathlen=strlen(ftpbuf);
  12956. int i=1;
  12957. char filenametemp[50];
  12958. while(i < ftppathlen)
  12959. {
  12960. int len=ftppathlen-i;
  12961. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12962. {
  12963. DEBUG_INFO(" compare '/' all right\n");
  12964. break;
  12965. }
  12966. i=i+1;
  12967. }
  12968. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12969. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12970. filenametemp[i+1] = 0;
  12971. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12972. pch=strchr(temp,'@');
  12973. if(pch==NULL)
  12974. {
  12975. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12976. protocol, host, &port, path);
  12977. strcpy(user,"anonymous");
  12978. strcpy(password,"");
  12979. }
  12980. else
  12981. {
  12982. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12983. protocol, user, password, host, &port, path);
  12984. }
  12985. sscanf(host,"%[^/]%s",host1, path1);
  12986. sprintf(ftppath,"%s", path1);
  12987. //DEBUG_INFO("protocol =%s\n",protocol);
  12988. //DEBUG_INFO("user =%s\n",user);
  12989. //DEBUG_INFO("password =%s\n",password);
  12990. //DEBUG_INFO("host1 =%s\n",host1);
  12991. //DEBUG_INFO("port =%d\n",port);
  12992. //DEBUG_INFO("path1 =%s\n",path1);
  12993. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12994. //ftpFile(host, user, password, port, ftppath, fname);
  12995. //download firmware pthred
  12996. if(port == 0)
  12997. {
  12998. port = 21;
  12999. }
  13000. do
  13001. {
  13002. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13003. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13004. sleep(1);
  13005. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13006. if(!isSuccess)
  13007. {
  13008. //BulldogUtil.sleepMs(interval*1000);
  13009. DEBUG_INFO("Update firmware request and download file fail.\n");
  13010. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13011. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13012. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13013. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13014. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13015. }
  13016. else
  13017. {
  13018. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13019. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13020. }
  13021. retriesInt--;
  13022. }while((!isSuccess)&&(retriesInt >= 0));
  13023. }
  13024. else
  13025. {
  13026. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13027. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13028. sleep(1);
  13029. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13030. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13031. }
  13032. // OCPPPH only, must announce CSU upgrade firmware
  13033. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13034. interLock.isUpdateFirmwareGoing = 0;
  13035. pthread_exit(NULL);
  13036. }
  13037. int handleCertificateSignedRequest(char *uuid, char *payload)
  13038. {
  13039. mtrace();
  13040. int result = PASS;
  13041. json_object *CertificateSigned;
  13042. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13043. CertificateSigned = json_tokener_parse(payload);
  13044. if(!is_error(CertificateSigned))
  13045. {
  13046. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13047. }
  13048. json_object_put(CertificateSigned);
  13049. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  13050. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  13051. fclose(fp);
  13052. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13053. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  13054. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  13055. sendCertificateSignedConfirmation(uuid);
  13056. return result;
  13057. }
  13058. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13059. {
  13060. mtrace();
  13061. int result = PASS;
  13062. json_object *DeleteCertificate;
  13063. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13064. DeleteCertificate = json_tokener_parse(payload);
  13065. if(!is_error(DeleteCertificate))
  13066. {
  13067. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13068. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13069. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13070. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13071. }
  13072. json_object_put(DeleteCertificate);
  13073. /*
  13074. * TODO: Delete certificateSigned process
  13075. */
  13076. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  13077. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  13078. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  13079. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  13080. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  13081. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  13082. sendDeleteCertificateConfirmation(uuid);
  13083. return result;
  13084. }
  13085. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13086. {
  13087. mtrace();
  13088. int result = PASS;
  13089. json_object *ExtendedTriggerMessage;
  13090. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13091. ExtendedTriggerMessage = json_tokener_parse(payload);
  13092. if(!is_error(ExtendedTriggerMessage))
  13093. {
  13094. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13095. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13096. {
  13097. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13098. }
  13099. else
  13100. {
  13101. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13102. }
  13103. }
  13104. json_object_put(ExtendedTriggerMessage);
  13105. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13106. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13107. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13108. {
  13109. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13110. }
  13111. else
  13112. {
  13113. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13114. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13115. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13116. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13117. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13118. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13119. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13120. {
  13121. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13122. }
  13123. else
  13124. {
  13125. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13126. }
  13127. }
  13128. sendExtendedTriggerMessageConfirmation(uuid);
  13129. //==========================
  13130. // Trigger message
  13131. //==========================
  13132. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13133. {
  13134. //sendBootNotificationRequest();
  13135. server_sign = FALSE;
  13136. }
  13137. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13138. {
  13139. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13140. }
  13141. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13142. {
  13143. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13144. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13145. {
  13146. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13147. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13148. }
  13149. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13150. }
  13151. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13152. {
  13153. refreshStartTimer(&clientTime.Heartbeat);
  13154. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13155. }
  13156. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13157. {
  13158. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13159. {
  13160. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13161. }
  13162. else
  13163. {
  13164. for(int idx=0;idx< gunTotalNumber;idx++)
  13165. {
  13166. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13167. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13168. }
  13169. }
  13170. }
  13171. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13172. {
  13173. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13174. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13175. {
  13176. 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\" &");
  13177. }
  13178. }
  13179. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13180. {
  13181. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13182. {
  13183. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13184. }
  13185. else
  13186. {
  13187. for(int idx=0;idx< gunTotalNumber;idx++)
  13188. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13189. }
  13190. }
  13191. return result;
  13192. }
  13193. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13194. {
  13195. mtrace();
  13196. int result = PASS;
  13197. json_object *GetInstalledCertificateIds;
  13198. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13199. GetInstalledCertificateIds = json_tokener_parse(payload);
  13200. if(!is_error(GetInstalledCertificateIds))
  13201. {
  13202. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13203. }
  13204. json_object_put(GetInstalledCertificateIds);
  13205. /*
  13206. * TODO: Return installed certificate process
  13207. */
  13208. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13209. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13210. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13211. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13212. sendGetInstalledCertificateIdsConfirmation(uuid);
  13213. return result;
  13214. }
  13215. int handleGetLogRequest(char *uuid, char *payload)
  13216. {
  13217. mtrace();
  13218. int result = PASS;
  13219. json_object *GetLog;
  13220. DEBUG_INFO("handleGetLogRequest...\n");
  13221. GetLog = json_tokener_parse(payload);
  13222. if(!is_error(GetLog))
  13223. {
  13224. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13225. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13226. if(json_object_object_get(GetLog, "retries") != NULL)
  13227. {
  13228. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13229. }
  13230. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13231. {
  13232. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13233. }
  13234. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13235. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13236. {
  13237. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13238. }
  13239. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13240. {
  13241. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13242. }
  13243. }
  13244. json_object_put(GetLog);
  13245. /*
  13246. * TODO: Upload log process
  13247. */
  13248. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13249. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13250. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13251. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13252. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13253. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13254. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13255. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13256. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13257. sendGetLogConfirmation(uuid);
  13258. return result;
  13259. }
  13260. int handleInstallCertificateRequest(char *uuid, char *payload)
  13261. {
  13262. mtrace();
  13263. int result = PASS;
  13264. json_object *InstallCertificate;
  13265. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13266. InstallCertificate = json_tokener_parse(payload);
  13267. if(!is_error(InstallCertificate))
  13268. {
  13269. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13270. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13271. /*
  13272. * TODO: Install certificate process
  13273. */
  13274. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13275. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13276. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13277. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13278. sendInstallCertificateConfirmation(uuid);
  13279. }
  13280. json_object_put(InstallCertificate);
  13281. return result;
  13282. }
  13283. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13284. {
  13285. mtrace();
  13286. int result = PASS;
  13287. json_object *SignedUpdateFirmware;
  13288. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13289. SignedUpdateFirmware = json_tokener_parse(payload);
  13290. if(!is_error(SignedUpdateFirmware))
  13291. {
  13292. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13293. {
  13294. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13295. }
  13296. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13297. {
  13298. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13299. }
  13300. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13301. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13302. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13303. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13304. {
  13305. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13306. }
  13307. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13308. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13309. }
  13310. json_object_put(SignedUpdateFirmware);
  13311. /*
  13312. * TODO: Upgrade firmware process
  13313. */
  13314. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13315. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13316. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13317. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13318. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13319. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13320. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13321. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13322. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13323. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13324. sendInstallCertificateConfirmation(uuid);
  13325. return result;
  13326. }
  13327. int handleUnknownRequest(char *uuid, char *payload)
  13328. {
  13329. mtrace();
  13330. int result = PASS;
  13331. DEBUG_INFO("handleUnknownRequest...\n");
  13332. sendUnknownConfirmation(uuid);
  13333. result = PASS;
  13334. return result;
  13335. }
  13336. //==========================================
  13337. // Handle server response routine
  13338. //==========================================
  13339. void handleAuthorizeResponse(char *payload, int gun_index)
  13340. {
  13341. mtrace();
  13342. char expiryDatestr[36]={0};
  13343. char parentIdTagstr[21]={0};
  13344. char statusstr[20]={0};
  13345. int expiryDateISNULL=FALSE;
  13346. int parentIdTagISNULL=FALSE;
  13347. DEBUG_INFO("handleAuthorizeResponse...\n");
  13348. json_object *Authorize;
  13349. Authorize = json_tokener_parse(payload);
  13350. if(!is_error(Authorize))
  13351. {
  13352. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13353. {
  13354. // Required data
  13355. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13356. // Optional data
  13357. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13358. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13359. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13360. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13361. }
  13362. }
  13363. json_object_put(Authorize);
  13364. if(expiryDateISNULL == FALSE)
  13365. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13366. if(parentIdTagISNULL == FALSE)
  13367. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13368. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13369. //Update idTag information to authorization cache if supproted
  13370. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13371. {
  13372. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13373. }
  13374. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13375. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13376. authorizeRetryTimes = 0;
  13377. }
  13378. void handleBootNotificationResponse(char *payload, int gun_index)
  13379. {
  13380. mtrace();
  13381. char statusStr[12]={0};
  13382. char currentTimeStr[30]={0};
  13383. int intervalInt = 0;
  13384. DEBUG_INFO("handleBootNotificationResponse...\n");
  13385. json_object *BootNotification;
  13386. BootNotification = json_tokener_parse(payload);
  13387. if(!is_error(BootNotification))
  13388. {
  13389. // Required data
  13390. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13391. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13392. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13393. }
  13394. json_object_put(BootNotification);
  13395. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13396. BootNotificationInterval = intervalInt;
  13397. //write back to ShmOCPP16DataPH->BootNotification
  13398. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13399. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13400. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13401. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13402. {
  13403. BootNotificationInterval = 0;
  13404. if((intervalInt == 0) || (intervalInt >= 10))
  13405. {
  13406. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13407. HeartBeatWaitTime = intervalInt;
  13408. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13409. }
  13410. server_sign = TRUE;
  13411. server_pending =FALSE;
  13412. }
  13413. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13414. {
  13415. server_pending = TRUE;
  13416. }
  13417. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13418. srand(time(NULL));
  13419. refreshStartTimer(&clientTime.Heartbeat);
  13420. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13421. SetOcppConnStatus(TRUE);
  13422. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13423. }
  13424. void handleDataTransferResponse(char *payload, int gun_index)
  13425. {
  13426. json_object *DataTransfer = json_tokener_parse(payload);
  13427. if(!is_error(DataTransfer))
  13428. {
  13429. // Required data
  13430. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13431. // Optional data
  13432. if(json_object_object_get(DataTransfer, "data") != NULL)
  13433. {
  13434. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13435. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13436. if(!is_error(Data))
  13437. {
  13438. if(json_object_object_get(Data, "msgId") != NULL)
  13439. {
  13440. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13441. {
  13442. 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")));
  13443. }
  13444. }
  13445. }
  13446. json_object_put(Data);
  13447. }
  13448. }
  13449. json_object_put(DataTransfer);
  13450. }
  13451. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13452. {
  13453. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13454. //struct json_object *obj;
  13455. // obj = json_tokener_parse(payload);
  13456. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13457. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13458. //No fields are defined.
  13459. }
  13460. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13461. {
  13462. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13463. //struct json_object *obj;
  13464. // obj = json_tokener_parse(payload);
  13465. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13466. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13467. //No fields are defined.
  13468. }
  13469. void handleHeartbeatResponse(char *payload, int gun_index)
  13470. {
  13471. mtrace();
  13472. DEBUG_INFO("handleHeartbeatResponse...\n");
  13473. json_object *Heartbeat;
  13474. Heartbeat = json_tokener_parse(payload);
  13475. if(!is_error(Heartbeat))
  13476. {
  13477. // Required data
  13478. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13479. }
  13480. json_object_put(Heartbeat);
  13481. if(FirstHeartBeat == 0)
  13482. {
  13483. FirstHeartBeat = 1;
  13484. DEBUG_INFO("FirstHeartBeat \n");
  13485. }
  13486. HeartBeatWithNOResponse = 0;
  13487. refreshStartTimer(&clientTime.Heartbeat);
  13488. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13489. }
  13490. void handleMeterValuesResponse(char *payload, int gun_index)
  13491. {
  13492. mtrace();
  13493. DEBUG_INFO("handleMeterValuesResponse...\n");
  13494. isQueueSendable = 1;
  13495. }
  13496. void handleStartTransactionResponse(char *payload, int gun_index)
  13497. {
  13498. mtrace();
  13499. //int transactionIdInt = 0;
  13500. FILE *outfile;
  13501. char data[100]={0};
  13502. DEBUG_INFO("handleStartTransactionResponse...\n");
  13503. json_object *StartTransaction;
  13504. StartTransaction = json_tokener_parse(payload);
  13505. if(!is_error(StartTransaction))
  13506. {
  13507. // Required data
  13508. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13509. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13510. // Optional data
  13511. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13512. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13513. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13514. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13515. }
  13516. json_object_put(StartTransaction);
  13517. isQueueSendable = 1;
  13518. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13519. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13520. //-----------Start : write to the Queue TransactionId file -----------------//
  13521. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13522. {}
  13523. else
  13524. {
  13525. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13526. if(log == NULL)
  13527. {
  13528. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13529. return ;
  13530. }
  13531. else
  13532. {
  13533. fclose(log);
  13534. }
  13535. }
  13536. // open file for writing
  13537. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13538. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13539. {
  13540. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13541. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13542. fputs(data, outfile);
  13543. fclose (outfile);
  13544. }
  13545. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13546. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13547. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13548. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13549. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13550. }
  13551. void handleStatusNotificationResponse(char *payload, int gun_index)
  13552. {
  13553. mtrace();
  13554. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13555. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13556. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13557. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13558. }
  13559. void handleStopTransactionnResponse(char *payload, int gun_index)
  13560. {
  13561. mtrace();
  13562. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13563. json_object *StopTransaction;
  13564. StopTransaction = json_tokener_parse(payload);
  13565. if(!is_error(StopTransaction))
  13566. {
  13567. // Optional data
  13568. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13569. {
  13570. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13571. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13572. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13573. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13574. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13575. }
  13576. }
  13577. json_object_put(StopTransaction);
  13578. isQueueSendable = 1;
  13579. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13580. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13581. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13582. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13583. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13584. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13585. }
  13586. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13587. {
  13588. mtrace();
  13589. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13590. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13591. }
  13592. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13593. {
  13594. mtrace();
  13595. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13596. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13597. }
  13598. void handleSignCertificateResponse(char *payload, int gun_index)
  13599. {
  13600. mtrace();
  13601. DEBUG_INFO("handleSignCertificateResponse...\n");
  13602. json_object *SignCertificate;
  13603. SignCertificate = json_tokener_parse(payload);
  13604. if(!is_error(SignCertificate))
  13605. {
  13606. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13607. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13608. }
  13609. json_object_put(SignCertificate);
  13610. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13611. }
  13612. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13613. {
  13614. mtrace();
  13615. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13616. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13617. }
  13618. //==========================================
  13619. // Handle Error routine
  13620. //==========================================
  13621. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13622. {
  13623. mtrace();
  13624. #ifdef SystemLogMessage
  13625. DEBUG_INFO("errorCode: %s\n", errorCode);
  13626. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13627. DEBUG_INFO("errorDetails: %s\n", payload);
  13628. #endif
  13629. }
  13630. //===============================================
  13631. // Common routine
  13632. //===============================================
  13633. int initialConfigurationTable(void)
  13634. {
  13635. //clock_t start_t, end_t, total_t;
  13636. FILE *fp;
  13637. FILE *outfile;
  13638. char str[512]={0};
  13639. char sstr[256]={0};
  13640. int c = 0;
  13641. char *loc;
  13642. int confVersion = 18;
  13643. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13644. //start_t = clock();
  13645. //printf("Starting of the program, start_t = %ld\n", start_t);
  13646. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13647. // Check configuration file size is correct
  13648. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13649. {
  13650. struct stat st;
  13651. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13652. if(st.st_size < 3100)
  13653. {
  13654. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13655. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13656. }
  13657. }
  13658. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13659. {
  13660. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13661. if(outfile == NULL)
  13662. {
  13663. DEBUG_INFO("Error opening file\n");
  13664. return FALSE;
  13665. }
  13666. /*Core Profile*/
  13667. //AllowOfflineTxForUnknownId
  13668. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13669. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13670. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13672. //AuthorizationCacheEnabled
  13673. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13674. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13675. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13677. //AuthorizeRemoteTxRequests
  13678. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13679. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13680. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13682. //BlinkRepeat
  13683. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13684. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13685. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13687. //ClockAlignedDataInterval
  13688. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13689. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13690. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13692. //ConnectionTimeOut
  13693. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13694. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13695. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13697. //GetConfigurationMaxKeys
  13698. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13699. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13700. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13702. // HeartbeatInterval
  13703. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13704. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13705. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13707. // LightIntensity
  13708. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13709. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13710. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13712. // LocalAuthorizeOffline
  13713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13714. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13715. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13717. // LocalPreAuthorize
  13718. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13719. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13720. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13722. // MaxEnergyOnInvalidId
  13723. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13724. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13725. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13727. // MeterValuesAlignedData
  13728. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13729. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13731. 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" );
  13732. else
  13733. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13735. // MeterValuesAlignedDataMaxLength
  13736. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13737. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13738. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13739. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13740. else
  13741. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13743. // MeterValuesSampledData
  13744. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13745. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13746. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13747. 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" );
  13748. else
  13749. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13751. // MeterValuesSampledDataMaxLength
  13752. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13753. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13754. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13755. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13756. else
  13757. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13758. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13759. // MeterValueSampleInterval
  13760. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13761. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13762. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13764. // MinimumStatusDuration
  13765. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13766. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13767. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13768. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13770. // NumberOfConnectors
  13771. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13772. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13773. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13774. {
  13775. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13776. }
  13777. else
  13778. {
  13779. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13780. }
  13781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13782. // ResetRetries
  13783. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13784. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13785. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13787. // ConnectorPhaseRotation
  13788. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13789. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13790. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13792. // ConnectorPhaseRotationMaxLength
  13793. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13794. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13795. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13797. // StopTransactionOnEVSideDisconnect
  13798. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13799. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13800. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13802. // StopTransactionOnInvalidId
  13803. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13804. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13807. // StopTxnAlignedData
  13808. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13809. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13810. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13812. // StopTxnAlignedDataMaxLength
  13813. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13814. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13815. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13817. // StopTxnSampledData
  13818. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13820. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13821. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13822. else
  13823. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13825. // StopTxnSampledDataMaxLength
  13826. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13827. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13828. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13829. {
  13830. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13831. }
  13832. else
  13833. {
  13834. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13835. }
  13836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13837. // SupportedFeatureProfiles
  13838. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13839. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13842. // SupportedFeatureProfilesMaxLength
  13843. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13847. // TransactionMessageAttempts
  13848. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13849. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13851. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13853. // TransactionMessageRetryInterval
  13854. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13856. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13857. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13859. // UnlockConnectorOnEVSideDisconnect
  13860. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13862. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13864. // WebSocketPingInterval
  13865. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13867. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13869. // QueueOffLineMeterValues
  13870. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13871. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13874. // AuthorizationKey
  13875. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13877. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13879. // SecurityProfile
  13880. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13881. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13882. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13884. // DefaultPrice
  13885. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13886. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13889. // CustomDisplayCostAndPrice
  13890. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13891. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13892. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13894. // CustomIdleFeeAfterStop
  13895. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13899. // SystemUptimeSec
  13900. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13901. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13902. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13904. // FreeVend
  13905. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13906. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13907. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13909. // FreeVendIdtag
  13910. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13911. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13912. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13914. // OcppServer
  13915. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13916. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13917. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13919. // MaintainServer
  13920. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13921. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13922. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13924. // StatusNotificationPeriodically
  13925. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13926. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13927. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13929. // StatusNotificationInterval
  13930. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13934. // isEnableLocalPowerSharing
  13935. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  13936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  13937. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  13938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  13939. // PowerSharingServerIP
  13940. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  13941. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  13942. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  13943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  13944. // EVCCID_PREFIX
  13945. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  13946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  13947. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  13948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  13949. // OffLineMaxChargingPower
  13950. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  13951. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  13952. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  13953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  13954. // Configuration Version
  13955. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13956. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13957. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13959. // Charging profile refresh interval
  13960. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  13961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  13962. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  13963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  13964. // Ocpp Software certificated version
  13965. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  13966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  13967. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  13968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  13969. //* Local Auth List Management Profile*/
  13970. #if 0
  13971. //For OCTT Test Case
  13972. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13973. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13974. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13975. #endif
  13976. #if 1
  13977. //LocalAuthListEnabled
  13978. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13979. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13982. #endif
  13983. //LocalAuthListMaxLength
  13984. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13985. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13988. //SendLocalListMaxLength
  13989. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13990. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13991. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  13992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13993. //ReserveConnectorZeroSupported
  13994. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13995. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13998. //* Smart Charging Profile */
  13999. //ChargeProfileMaxStackLevel
  14000. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14004. // ChargingScheduleAllowedChargingRateUnit
  14005. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14009. // ChargingScheduleMaxPeriods
  14010. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14011. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14012. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14013. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14014. // ConnectorSwitch3to1PhaseSupported
  14015. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14017. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14019. // MaxChargingProfilesInstalled
  14020. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14022. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14024. fclose(outfile);
  14025. }
  14026. else
  14027. {
  14028. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  14029. char keystr[60]={0};
  14030. char readonlystr[10]={0};
  14031. char valuestr[256]={0};
  14032. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  14033. if(fp == NULL) {
  14034. DEBUG_INFO("Error opening file");
  14035. return FALSE;
  14036. }
  14037. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14038. {
  14039. //DEBUG_INFO("Get Configuration \n");
  14040. if(strlen(str) > 0)
  14041. {
  14042. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14043. //*************************key*********************************/
  14044. if(strstr(str, "key") != NULL)
  14045. {
  14046. loc = strstr(str, "key");
  14047. c = 0;
  14048. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14049. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14050. {
  14051. sstr[c] = loc[strlen("key")+3+c];
  14052. c++;
  14053. }
  14054. sstr[c] = '\0';
  14055. strcpy(keystr,sstr);
  14056. }
  14057. //*************************readonly*********************************/
  14058. if(strstr(str, "readonly") != NULL)
  14059. {
  14060. loc = strstr(str, "readonly");
  14061. c = 0;
  14062. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14063. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14064. {
  14065. sstr[c] = loc[strlen("readonly")+2+c];
  14066. c++;
  14067. }
  14068. sstr[c] = '\0';
  14069. strcpy(readonlystr,sstr);
  14070. }
  14071. //*************************value*********************************/
  14072. if(strstr(str, "value") != NULL)
  14073. {
  14074. loc = strstr(str, "value");
  14075. c = 0;
  14076. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14077. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14078. {
  14079. sstr[c] = loc[strlen("value")+3+c];
  14080. c++;
  14081. }
  14082. sstr[c] = '\0';
  14083. strcpy(valuestr,sstr);
  14084. }
  14085. // DEBUG_INFO("keystr=%s\n",keystr);
  14086. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14087. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14088. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14089. {
  14090. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14091. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14092. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14093. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14094. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14095. }
  14096. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14097. {
  14098. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14099. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14100. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14101. }
  14102. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14103. {
  14104. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14105. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14106. }
  14107. if(strcmp(keystr, "BlinkRepeat") == 0)
  14108. {
  14109. //Charger.BlinkRepeat = Integer.parseInt(value);
  14110. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14111. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14112. }
  14113. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14114. {
  14115. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14116. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14117. }
  14118. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14119. {
  14120. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14121. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14122. }
  14123. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14124. {
  14125. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14126. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14127. }
  14128. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14129. {
  14130. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14131. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14132. HeartBeatWaitTime = atoi(valuestr);
  14133. }
  14134. if(strcmp(keystr, "LightIntensity") == 0)
  14135. {
  14136. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14137. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14138. }
  14139. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14140. {
  14141. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14142. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14143. }
  14144. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14145. {
  14146. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14147. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14148. }
  14149. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14150. {
  14151. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14152. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14153. }
  14154. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14155. {
  14156. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14157. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14158. }
  14159. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14160. {
  14161. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14162. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14163. }
  14164. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14165. {
  14166. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14167. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14168. }
  14169. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14170. {
  14171. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14172. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14173. }
  14174. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14175. {
  14176. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14177. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14178. }
  14179. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14180. {
  14181. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14182. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14183. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14184. }
  14185. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14186. {
  14187. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14188. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14189. }
  14190. if(strcmp(keystr, "ResetRetries") == 0)
  14191. {
  14192. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14193. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14194. }
  14195. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14196. {
  14197. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14198. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14199. }
  14200. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14201. {
  14202. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14203. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14204. }
  14205. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14206. {
  14207. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14208. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14209. }
  14210. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14211. {
  14212. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14213. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14214. }
  14215. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14216. {
  14217. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14218. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14219. }
  14220. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14221. {
  14222. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14223. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14224. }
  14225. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14226. {
  14227. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14228. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14229. }
  14230. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14231. {
  14232. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14233. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14234. }
  14235. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14236. {
  14237. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14238. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14239. }
  14240. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14241. {
  14242. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14243. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14244. }
  14245. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14246. {
  14247. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14248. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14249. TransactionMessageAttemptsValue = atoi(valuestr);
  14250. }
  14251. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14252. {
  14253. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14254. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14255. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14256. }
  14257. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14258. {
  14259. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14260. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14261. }
  14262. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14263. {
  14264. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14265. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14266. }
  14267. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14268. {
  14269. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14270. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14271. }
  14272. if(strcmp(keystr, "AuthorizationKey") == 0)
  14273. {
  14274. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14275. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14276. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14277. }
  14278. if(strcmp(keystr, "SecurityProfile") == 0)
  14279. {
  14280. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14281. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14282. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14283. }
  14284. if(strcmp(keystr, "DefaultPrice") == 0)
  14285. {
  14286. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14287. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14288. }
  14289. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14290. {
  14291. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14292. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14293. }
  14294. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14295. {
  14296. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14297. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14298. }
  14299. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14300. {
  14301. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14302. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14303. }
  14304. if(strcmp(keystr, "FreeVend") == 0)
  14305. {
  14306. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14307. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14308. }
  14309. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14310. {
  14311. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14312. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14313. }
  14314. if(strcmp(keystr, "OcppServer") == 0)
  14315. {
  14316. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14317. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14318. }
  14319. if(strcmp(keystr, "MaintainServer") == 0)
  14320. {
  14321. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14322. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14323. }
  14324. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14325. {
  14326. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14327. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14328. }
  14329. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14330. {
  14331. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14332. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14333. }
  14334. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14335. {
  14336. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14337. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14338. }
  14339. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14340. {
  14341. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14342. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14343. }
  14344. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14345. {
  14346. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14347. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14348. }
  14349. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  14350. {
  14351. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14352. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  14353. }
  14354. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14355. {
  14356. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14357. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14358. }
  14359. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  14360. {
  14361. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14362. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  14363. }
  14364. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  14365. {
  14366. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14367. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  14368. }
  14369. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14370. {
  14371. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14372. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14373. }
  14374. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14375. {
  14376. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14377. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14378. }
  14379. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14380. {
  14381. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14382. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14383. }
  14384. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14385. {
  14386. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14387. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14388. }
  14389. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14390. {
  14391. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14392. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14393. }
  14394. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14395. {
  14396. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14397. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14398. }
  14399. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14400. {
  14401. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14402. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14403. }
  14404. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14405. {
  14406. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14407. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14408. }
  14409. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14410. {
  14411. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14412. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14413. }
  14414. }
  14415. }
  14416. fclose(fp);
  14417. }
  14418. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14419. {
  14420. return PASS;
  14421. }
  14422. else
  14423. {
  14424. return FAIL;
  14425. }
  14426. }
  14427. void StoreConfigurationTable(void)
  14428. {
  14429. FILE *outfile;
  14430. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14431. if(outfile == NULL)
  14432. {
  14433. DEBUG_INFO("Error opening file");
  14434. return ;
  14435. }
  14436. /*Core Profile*/
  14437. //AllowOfflineTxForUnknownId
  14438. /*
  14439. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14440. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14441. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14442. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14443. */
  14444. //DEBUG_INFO("data=%s\n",data);
  14445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14446. //AuthorizationCacheEnabled
  14447. /*
  14448. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14449. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14450. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14451. */
  14452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14453. //AuthorizeRemoteTxRequests
  14454. /*
  14455. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14456. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14457. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14458. */
  14459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14460. //BlinkRepeat
  14461. /*
  14462. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14463. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14464. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14465. */
  14466. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14467. //ClockAlignedDataInterval
  14468. /*
  14469. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14470. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14471. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14472. */
  14473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14474. //ConnectionTimeOut
  14475. /*
  14476. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14477. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14478. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14479. */
  14480. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14481. //GetConfigurationMaxKeys
  14482. /*
  14483. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14484. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14485. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14486. */
  14487. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14488. // HeartbeatInterval
  14489. /*
  14490. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14491. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14492. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14493. */
  14494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14495. // LightIntensity
  14496. /*
  14497. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14498. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14499. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14500. */
  14501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14502. // LocalAuthorizeOffline
  14503. /*
  14504. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14505. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14506. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14507. */
  14508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14509. // LocalPreAuthorize
  14510. /*
  14511. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14512. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14513. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14514. */
  14515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14516. // MaxEnergyOnInvalidId
  14517. /*
  14518. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14519. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14520. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14521. */
  14522. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14524. // MeterValuesAlignedData
  14525. /*
  14526. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14527. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14528. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14529. */
  14530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14531. // MeterValuesAlignedDataMaxLength
  14532. /*
  14533. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14534. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14535. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14536. */
  14537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14538. // MeterValuesSampledData
  14539. /*
  14540. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14541. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14542. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14543. */
  14544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14545. // MeterValuesSampledDataMaxLength
  14546. /*
  14547. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14548. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14549. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14550. */
  14551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14552. // MeterValueSampleInterval
  14553. /*
  14554. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14555. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14556. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14557. */
  14558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14559. // MinimumStatusDuration
  14560. /*
  14561. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14562. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14563. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14564. */
  14565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14566. // NumberOfConnectors
  14567. /*
  14568. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14569. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14571. {
  14572. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14573. }
  14574. else
  14575. {
  14576. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14577. }
  14578. */
  14579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14580. // ResetRetries
  14581. /*
  14582. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14583. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14584. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14585. */
  14586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14587. // ConnectorPhaseRotation
  14588. /*
  14589. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14590. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14591. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14592. */
  14593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14594. // ConnectorPhaseRotationMaxLength
  14595. /*
  14596. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14597. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14598. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14599. */
  14600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14601. // StopTransactionOnEVSideDisconnect
  14602. /*
  14603. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14604. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14605. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14606. */
  14607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14608. // StopTransactionOnInvalidId
  14609. /*
  14610. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14611. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14612. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14613. */
  14614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14615. // StopTxnAlignedData
  14616. /*
  14617. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14618. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14619. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14620. */
  14621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14622. // StopTxnAlignedDataMaxLength
  14623. /*
  14624. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14625. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14626. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14627. */
  14628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14629. // StopTxnSampledData
  14630. /*
  14631. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14632. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14633. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14634. */
  14635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14636. // StopTxnSampledDataMaxLength
  14637. /*
  14638. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14639. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14640. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14641. */
  14642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14643. // SupportedFeatureProfiles
  14644. /*
  14645. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14646. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14647. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14648. */
  14649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14650. // SupportedFeatureProfilesMaxLength
  14651. /*
  14652. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14653. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14654. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14655. */
  14656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14657. // TransactionMessageAttempts
  14658. /*
  14659. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14660. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14661. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14662. */
  14663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14664. // TransactionMessageRetryInterval
  14665. /*
  14666. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14667. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14668. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14669. */
  14670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14671. // UnlockConnectorOnEVSideDisconnect
  14672. /*
  14673. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14674. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14675. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14676. */
  14677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14678. // WebSocketPingInterval
  14679. /*
  14680. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14681. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14682. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14683. */
  14684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14685. // QueueOffLineMeterValues
  14686. /*
  14687. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14688. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14689. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14690. */
  14691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14692. // AuthorizationKey
  14693. /*
  14694. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14695. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14696. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14697. */
  14698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14699. // SecurityProfile
  14700. /*
  14701. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14702. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14703. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14704. */
  14705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14706. // DefaultPrice
  14707. /*
  14708. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14709. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14710. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14711. */
  14712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14713. // CustomDisplayCostAndPrice
  14714. /*
  14715. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14716. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14717. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14718. */
  14719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14720. // CustomIdleFeeAfterStop
  14721. /*
  14722. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14723. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14724. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14725. */
  14726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14727. // SystemUptimeSec
  14728. /*
  14729. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14730. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14731. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14732. */
  14733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14734. // FreeVend
  14735. /*
  14736. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14737. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14738. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14739. */
  14740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14741. // FreeVendIdtag
  14742. /*
  14743. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14744. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14745. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14746. */
  14747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14748. // OcppServer
  14749. /*
  14750. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14751. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14752. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14753. */
  14754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14755. // MaintainServer
  14756. /*
  14757. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14758. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14759. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14760. */
  14761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14762. // StatusNotificationPeriodically
  14763. /*
  14764. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14765. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14766. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14767. */
  14768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14769. // StatusNotificationInterval
  14770. /*
  14771. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14772. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14773. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14774. */
  14775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14776. // isEnableLocalPowerSharing
  14777. /*
  14778. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  14781. */
  14782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14783. // PowerSharingServerIP
  14784. /*
  14785. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  14788. */
  14789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14790. // EVCCID_PREFIX
  14791. /*
  14792. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14795. */
  14796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14797. // OffLineMaxChargingPower
  14798. /*
  14799. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  14800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  14801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  14802. */
  14803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  14804. // ConfigurationVersion
  14805. /*
  14806. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14807. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14808. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14809. */
  14810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14811. // CharingProfileRefreshInterval
  14812. /*
  14813. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  14814. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  14815. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  14816. */
  14817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  14818. // OcppSoftwareVersion
  14819. /*
  14820. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  14821. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  14822. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  14823. */
  14824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  14825. //* Local Auth List Management Profile*/
  14826. //LocalAuthListEnabled
  14827. /*
  14828. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14831. */
  14832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14833. //LocalAuthListMaxLength
  14834. /*
  14835. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14836. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14837. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14838. */
  14839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14840. //SendLocalListMaxLength
  14841. /*
  14842. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14843. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14845. */
  14846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14847. //ReserveConnectorZeroSupported
  14848. /*
  14849. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14852. */
  14853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14854. //* Smart Charging Profile */
  14855. //ChargeProfileMaxStackLevel
  14856. /*
  14857. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14858. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14860. */
  14861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14862. // ChargingScheduleAllowedChargingRateUnit
  14863. /*
  14864. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14867. */
  14868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14869. // ChargingScheduleMaxPeriods
  14870. /*
  14871. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14873. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14874. */
  14875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14876. // ConnectorSwitch3to1PhaseSupported
  14877. /*
  14878. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14879. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14880. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14881. */
  14882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14883. // MaxChargingProfilesInstalled
  14884. /*
  14885. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14886. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14888. */
  14889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14890. fclose(outfile);
  14891. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14892. }
  14893. void getKeyValue(char *keyReq)
  14894. {
  14895. int isEmpty = FALSE;
  14896. int isKnowKey = FALSE;
  14897. DEBUG_INFO("keyReq = %s\n", keyReq);
  14898. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14899. isEmpty = TRUE;
  14900. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14901. {
  14902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14904. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14905. {
  14906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14907. }
  14908. else
  14909. {
  14910. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14911. }
  14912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14913. isKnowKey = TRUE;
  14914. }
  14915. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14916. {
  14917. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14918. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14919. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14920. {
  14921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14922. }
  14923. else
  14924. {
  14925. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14926. }
  14927. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14928. isKnowKey = TRUE;
  14929. }
  14930. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14931. {
  14932. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14934. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14935. {
  14936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14937. }
  14938. else
  14939. {
  14940. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14941. }
  14942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14943. isKnowKey = TRUE;
  14944. }
  14945. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14946. {
  14947. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14949. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14950. {
  14951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14952. }
  14953. else
  14954. {
  14955. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14956. }
  14957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14958. isKnowKey = TRUE;
  14959. }
  14960. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14961. {
  14962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14963. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14964. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14965. {
  14966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14967. }
  14968. else
  14969. {
  14970. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14971. }
  14972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14973. isKnowKey = TRUE;
  14974. }
  14975. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14976. {
  14977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14978. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14979. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14980. {
  14981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14982. }
  14983. else
  14984. {
  14985. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14986. }
  14987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14988. isKnowKey = TRUE;
  14989. }
  14990. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14991. {
  14992. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14994. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14995. {
  14996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14997. }
  14998. else
  14999. {
  15000. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15001. }
  15002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15003. isKnowKey = TRUE;
  15004. }
  15005. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15006. {
  15007. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15008. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15009. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15010. {
  15011. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15012. }
  15013. else
  15014. {
  15015. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15016. }
  15017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15018. isKnowKey = TRUE;
  15019. }
  15020. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15021. {
  15022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15023. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15024. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15025. {
  15026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15027. }
  15028. else
  15029. {
  15030. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15031. }
  15032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15033. isKnowKey = TRUE;
  15034. }
  15035. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15036. {
  15037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15038. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15039. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15040. {
  15041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15042. }
  15043. else
  15044. {
  15045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15046. }
  15047. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15048. isKnowKey = TRUE;
  15049. }
  15050. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15051. {
  15052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15053. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15054. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15055. {
  15056. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15057. }
  15058. else
  15059. {
  15060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15061. }
  15062. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15063. isKnowKey = TRUE;
  15064. }
  15065. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15066. {
  15067. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15068. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15069. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15070. {
  15071. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15072. }
  15073. else
  15074. {
  15075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15076. }
  15077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15078. isKnowKey = TRUE;
  15079. }
  15080. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15081. {
  15082. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15083. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15084. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15085. {
  15086. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15087. }
  15088. else
  15089. {
  15090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15091. }
  15092. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15093. isKnowKey = TRUE;
  15094. }
  15095. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15096. {
  15097. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15098. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15099. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15100. {
  15101. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15102. }
  15103. else
  15104. {
  15105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15106. }
  15107. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15108. isKnowKey = TRUE;
  15109. }
  15110. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15111. {
  15112. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15113. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15114. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15115. {
  15116. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15117. }
  15118. else
  15119. {
  15120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15121. }
  15122. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15123. isKnowKey = TRUE;
  15124. }
  15125. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15126. {
  15127. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15128. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15129. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15130. {
  15131. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15132. }
  15133. else
  15134. {
  15135. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15136. }
  15137. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15138. isKnowKey = TRUE;
  15139. }
  15140. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15141. {
  15142. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15143. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15144. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15145. {
  15146. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15147. }
  15148. else
  15149. {
  15150. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15151. }
  15152. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15153. isKnowKey = TRUE;
  15154. }
  15155. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15156. {
  15157. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15158. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15159. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15160. {
  15161. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15162. }
  15163. else
  15164. {
  15165. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15166. }
  15167. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  15168. isKnowKey = TRUE;
  15169. }
  15170. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15171. {
  15172. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15173. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15174. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15175. {
  15176. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15177. }
  15178. else
  15179. {
  15180. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15181. }
  15182. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15183. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15184. isKnowKey = TRUE;
  15185. }
  15186. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15187. {
  15188. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15189. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15190. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15191. {
  15192. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15193. }
  15194. else
  15195. {
  15196. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15197. }
  15198. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15199. isKnowKey = TRUE;
  15200. }
  15201. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15202. {
  15203. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15204. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15205. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15206. {
  15207. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15208. }
  15209. else
  15210. {
  15211. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15212. }
  15213. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15214. isKnowKey = TRUE;
  15215. }
  15216. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15217. {
  15218. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15219. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15220. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15221. {
  15222. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15223. }
  15224. else
  15225. {
  15226. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15227. }
  15228. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15229. isKnowKey = TRUE;
  15230. }
  15231. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15232. {
  15233. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15234. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15235. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15236. {
  15237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15238. }
  15239. else
  15240. {
  15241. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15242. }
  15243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15244. isKnowKey = TRUE;
  15245. }
  15246. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15247. {
  15248. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15249. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15250. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15251. {
  15252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15253. }
  15254. else
  15255. {
  15256. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15257. }
  15258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15259. isKnowKey = TRUE;
  15260. }
  15261. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15262. {
  15263. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15264. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15265. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15266. {
  15267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15268. }
  15269. else
  15270. {
  15271. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15272. }
  15273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15274. isKnowKey = TRUE;
  15275. }
  15276. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15277. {
  15278. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15279. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15280. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15281. {
  15282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15283. }
  15284. else
  15285. {
  15286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15287. }
  15288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15289. isKnowKey = TRUE;
  15290. }
  15291. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15292. {
  15293. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15294. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15295. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15296. {
  15297. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15298. }
  15299. else
  15300. {
  15301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15302. }
  15303. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15304. isKnowKey = TRUE;
  15305. }
  15306. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15307. {
  15308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15310. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15311. {
  15312. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15313. }
  15314. else
  15315. {
  15316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15317. }
  15318. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15319. isKnowKey = TRUE;
  15320. }
  15321. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15322. {
  15323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15325. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15326. {
  15327. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15328. }
  15329. else
  15330. {
  15331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15332. }
  15333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15334. isKnowKey = TRUE;
  15335. }
  15336. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15337. {
  15338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15340. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15341. {
  15342. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15343. }
  15344. else
  15345. {
  15346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15347. }
  15348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15349. isKnowKey = TRUE;
  15350. }
  15351. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15352. {
  15353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15355. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15356. {
  15357. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15358. }
  15359. else
  15360. {
  15361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15362. }
  15363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15364. isKnowKey = TRUE;
  15365. }
  15366. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15367. {
  15368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15370. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15371. {
  15372. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15373. }
  15374. else
  15375. {
  15376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15377. }
  15378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15379. isKnowKey = TRUE;
  15380. }
  15381. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15382. {
  15383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15385. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15386. {
  15387. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15388. }
  15389. else
  15390. {
  15391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15392. }
  15393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15394. isKnowKey = TRUE;
  15395. }
  15396. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15397. {
  15398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15400. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15401. {
  15402. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15403. }
  15404. else
  15405. {
  15406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15407. }
  15408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15409. isKnowKey = TRUE;
  15410. }
  15411. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15412. {
  15413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15415. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15416. {
  15417. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15418. }
  15419. else
  15420. {
  15421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15422. }
  15423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15424. isKnowKey = TRUE;
  15425. }
  15426. /*
  15427. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15428. {
  15429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15431. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15432. {
  15433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15434. }
  15435. else
  15436. {
  15437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15438. }
  15439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15440. isKnowKey = TRUE;
  15441. }*/
  15442. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15443. {
  15444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15446. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15447. {
  15448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15449. }
  15450. else
  15451. {
  15452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15453. }
  15454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15455. isKnowKey = TRUE;
  15456. }
  15457. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15458. {
  15459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15461. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15462. {
  15463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15464. }
  15465. else
  15466. {
  15467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15468. }
  15469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15470. isKnowKey = TRUE;
  15471. }
  15472. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15473. {
  15474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15476. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15477. {
  15478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15479. }
  15480. else
  15481. {
  15482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15483. }
  15484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15485. isKnowKey = TRUE;
  15486. }
  15487. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15488. {
  15489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15490. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15491. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15492. {
  15493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15494. }
  15495. else
  15496. {
  15497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15498. }
  15499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15500. isKnowKey = TRUE;
  15501. }
  15502. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15503. {
  15504. struct sysinfo s_info;
  15505. int error = sysinfo(&s_info);
  15506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15508. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15509. {
  15510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15511. }
  15512. else
  15513. {
  15514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15515. }
  15516. if(error != 0)
  15517. {
  15518. DEBUG_WARN("System uptime get error: %d\n", error);
  15519. }
  15520. else
  15521. {
  15522. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15523. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15524. }
  15525. isKnowKey = TRUE;
  15526. }
  15527. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15528. {
  15529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15531. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15532. {
  15533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15534. }
  15535. else
  15536. {
  15537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15538. }
  15539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15540. isKnowKey = TRUE;
  15541. }
  15542. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15543. {
  15544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15546. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15547. {
  15548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15549. }
  15550. else
  15551. {
  15552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15553. }
  15554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15555. isKnowKey = TRUE;
  15556. }
  15557. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15558. {
  15559. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15561. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15562. {
  15563. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15564. }
  15565. else
  15566. {
  15567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15568. }
  15569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15570. isKnowKey = TRUE;
  15571. }
  15572. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15573. {
  15574. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15576. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15577. {
  15578. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15579. }
  15580. else
  15581. {
  15582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15583. }
  15584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15585. isKnowKey = TRUE;
  15586. }
  15587. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15588. {
  15589. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15591. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15592. {
  15593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15594. }
  15595. else
  15596. {
  15597. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15598. }
  15599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15600. isKnowKey = TRUE;
  15601. }
  15602. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15603. {
  15604. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15605. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15606. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15607. {
  15608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15609. }
  15610. else
  15611. {
  15612. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15613. }
  15614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15615. isKnowKey = TRUE;
  15616. }
  15617. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  15618. {
  15619. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  15620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  15621. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  15622. {
  15623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  15624. }
  15625. else
  15626. {
  15627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  15628. }
  15629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  15630. isKnowKey = TRUE;
  15631. }
  15632. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  15633. {
  15634. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  15635. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  15636. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  15637. {
  15638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  15639. }
  15640. else
  15641. {
  15642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  15643. }
  15644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  15645. isKnowKey = TRUE;
  15646. }
  15647. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  15648. {
  15649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  15650. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  15651. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  15652. {
  15653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  15654. }
  15655. else
  15656. {
  15657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  15658. }
  15659. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  15660. isKnowKey = TRUE;
  15661. }
  15662. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  15663. {
  15664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  15665. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  15666. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  15667. {
  15668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  15669. }
  15670. else
  15671. {
  15672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  15673. }
  15674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  15675. isKnowKey = TRUE;
  15676. }
  15677. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15678. {
  15679. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15680. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15681. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15682. {
  15683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15684. }
  15685. else
  15686. {
  15687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15688. }
  15689. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15690. isKnowKey = TRUE;
  15691. }
  15692. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  15693. {
  15694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  15695. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  15696. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  15697. {
  15698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  15699. }
  15700. else
  15701. {
  15702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  15703. }
  15704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  15705. isKnowKey = TRUE;
  15706. }
  15707. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  15708. {
  15709. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  15710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  15711. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  15712. {
  15713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  15714. }
  15715. else
  15716. {
  15717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  15718. }
  15719. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  15720. isKnowKey = TRUE;
  15721. }
  15722. #if 1
  15723. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15724. {
  15725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15727. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15728. {
  15729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15730. }
  15731. else
  15732. {
  15733. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15734. }
  15735. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15736. isKnowKey = TRUE;
  15737. }
  15738. #endif
  15739. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15740. {
  15741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15742. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15743. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15744. {
  15745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15746. }
  15747. else
  15748. {
  15749. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15750. }
  15751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15752. isKnowKey = TRUE;
  15753. }
  15754. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15755. {
  15756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15757. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15758. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15759. {
  15760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15761. }
  15762. else
  15763. {
  15764. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15765. }
  15766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15767. isKnowKey = TRUE;
  15768. }
  15769. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15770. {
  15771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15772. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15773. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15774. {
  15775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15776. }
  15777. else
  15778. {
  15779. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15780. }
  15781. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15782. isKnowKey = TRUE;
  15783. }
  15784. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15785. {
  15786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15787. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15788. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15789. {
  15790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15791. }
  15792. else
  15793. {
  15794. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15795. }
  15796. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15797. isKnowKey = TRUE;
  15798. }
  15799. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15800. {
  15801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15802. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15803. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15804. {
  15805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15806. }
  15807. else
  15808. {
  15809. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15810. }
  15811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15812. isKnowKey = TRUE;
  15813. }
  15814. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15815. {
  15816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15817. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15818. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15819. {
  15820. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15821. }
  15822. else
  15823. {
  15824. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15825. }
  15826. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15827. isKnowKey = TRUE;
  15828. }
  15829. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15830. {
  15831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15832. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15833. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15834. {
  15835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15836. }
  15837. else
  15838. {
  15839. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15840. }
  15841. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15842. isKnowKey = TRUE;
  15843. }
  15844. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15845. {
  15846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15847. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15848. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15849. {
  15850. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15851. }
  15852. else
  15853. {
  15854. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15855. }
  15856. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15857. isKnowKey = TRUE;
  15858. }
  15859. //=========================================================
  15860. if(!isEmpty && !isKnowKey)
  15861. {
  15862. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15863. strcpy(unknownkey[UnknownKeynum], keyReq);
  15864. UnknownKeynum = UnknownKeynum + 1;
  15865. }
  15866. }
  15867. void processUnkownKey(void)
  15868. {
  15869. DEBUG_INFO("processUnkownKey...\n");
  15870. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15871. for(int index=0; index < UnknownKeynum; index++)
  15872. {
  15873. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15874. {
  15875. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15876. }
  15877. }
  15878. }
  15879. int setKeyValue(char *key, char *value)
  15880. {
  15881. int isSuccess = NotSupported;
  15882. int check_ascii=0;
  15883. char str[501]={0};
  15884. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15885. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15886. {
  15887. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15888. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15889. {
  15890. strcpy(str, (const char*)value);
  15891. for(int i = 0; str[i]; i++){
  15892. str[i] = tolower(str[i]);
  15893. }
  15894. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15895. isSuccess = ConfigurationStatus_Accepted;
  15896. }
  15897. else
  15898. {
  15899. isSuccess = ConfigurationStatus_Rejected;
  15900. }
  15901. }
  15902. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15903. {
  15904. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15905. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15906. {
  15907. strcpy(str, (const char*)value);
  15908. for(int i = 0; str[i]; i++){
  15909. str[i] = tolower(str[i]);
  15910. }
  15911. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15912. isSuccess = ConfigurationStatus_Accepted;
  15913. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15914. }
  15915. else
  15916. {
  15917. isSuccess = ConfigurationStatus_Rejected;
  15918. }
  15919. }
  15920. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15921. {
  15922. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15923. {
  15924. strcpy(str, (const char*)value);
  15925. for(int i = 0; str[i]; i++)
  15926. {
  15927. str[i] = tolower(str[i]);
  15928. }
  15929. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15930. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15931. isSuccess = ConfigurationStatus_Accepted;
  15932. }
  15933. else
  15934. {
  15935. isSuccess = ConfigurationStatus_Rejected;
  15936. }
  15937. }
  15938. if(strcmp(key, "BlinkRepeat") == 0)
  15939. {
  15940. //Charger.BlinkRepeat = Integer.parseInt(value);
  15941. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15942. {
  15943. check_ascii = value[0];
  15944. if( (check_ascii < 48) || (check_ascii > 57) )
  15945. {
  15946. isSuccess = ConfigurationStatus_Rejected;
  15947. }
  15948. else
  15949. {
  15950. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15951. isSuccess = ConfigurationStatus_Accepted;
  15952. }
  15953. }
  15954. else
  15955. {
  15956. isSuccess = ConfigurationStatus_Rejected;
  15957. }
  15958. }
  15959. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15960. {
  15961. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15962. {
  15963. check_ascii = value[0];
  15964. if( (check_ascii < 48) || (check_ascii > 57) )
  15965. {
  15966. isSuccess = ConfigurationStatus_Rejected;
  15967. }
  15968. else
  15969. {
  15970. if((atoi(value) == 0) || (atoi(value) >= 5))
  15971. {
  15972. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15973. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15974. isSuccess = ConfigurationStatus_Accepted;
  15975. }
  15976. else
  15977. isSuccess = ConfigurationStatus_Rejected;
  15978. }
  15979. }
  15980. else
  15981. {
  15982. isSuccess = ConfigurationStatus_Rejected;
  15983. }
  15984. }
  15985. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15986. {
  15987. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15988. {
  15989. check_ascii = value[0];
  15990. if( (check_ascii < 48) || (check_ascii > 57) )
  15991. {
  15992. isSuccess = ConfigurationStatus_Rejected;
  15993. }
  15994. else
  15995. {
  15996. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15997. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15998. isSuccess = ConfigurationStatus_Accepted;
  15999. }
  16000. }
  16001. else
  16002. {
  16003. isSuccess = ConfigurationStatus_Rejected;
  16004. }
  16005. }
  16006. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16007. {
  16008. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16009. {
  16010. check_ascii = value[0];
  16011. if( (check_ascii < 48) || (check_ascii > 57) )
  16012. {
  16013. isSuccess = ConfigurationStatus_Rejected;
  16014. }
  16015. else
  16016. {
  16017. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16018. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16019. isSuccess = ConfigurationStatus_Accepted;
  16020. }
  16021. }
  16022. else
  16023. {
  16024. isSuccess = ConfigurationStatus_Rejected;
  16025. }
  16026. }
  16027. if(strcmp(key, "HeartbeatInterval") == 0)
  16028. {
  16029. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16030. {
  16031. check_ascii = value[0];
  16032. if( (check_ascii < 48) || (check_ascii > 57) )
  16033. {
  16034. isSuccess = ConfigurationStatus_Rejected;
  16035. }
  16036. else
  16037. {
  16038. if((atoi(value) == 0) || (atoi(value) >= 10))
  16039. {
  16040. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16041. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16042. HeartBeatWaitTime = atoi(value);
  16043. isSuccess = ConfigurationStatus_Accepted;
  16044. }
  16045. else
  16046. {
  16047. isSuccess = ConfigurationStatus_Rejected;
  16048. }
  16049. }
  16050. }
  16051. else
  16052. {
  16053. isSuccess = ConfigurationStatus_Rejected;
  16054. }
  16055. }
  16056. if(strcmp(key, "LightIntensity") == 0)
  16057. {
  16058. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16059. {
  16060. check_ascii = value[0];
  16061. if( (check_ascii < 48) || (check_ascii > 57) )
  16062. {
  16063. isSuccess = ConfigurationStatus_Rejected;
  16064. }
  16065. else
  16066. {
  16067. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16068. isSuccess = ConfigurationStatus_Accepted;
  16069. }
  16070. }
  16071. else
  16072. {
  16073. isSuccess = ConfigurationStatus_Rejected;
  16074. }
  16075. }
  16076. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16077. {
  16078. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16079. {
  16080. strcpy(str, (const char*)value);
  16081. for(int i = 0; str[i]; i++)
  16082. {
  16083. str[i] = tolower(str[i]);
  16084. }
  16085. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16086. isSuccess = ConfigurationStatus_Accepted;
  16087. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16088. }
  16089. else
  16090. {
  16091. isSuccess = ConfigurationStatus_Rejected;
  16092. }
  16093. }
  16094. if(strcmp(key, "LocalPreAuthorize") == 0)
  16095. {
  16096. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16097. {
  16098. strcpy(str, (const char*)value);
  16099. for(int i = 0; str[i]; i++)
  16100. {
  16101. str[i] = tolower(str[i]);
  16102. }
  16103. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16104. isSuccess = ConfigurationStatus_Accepted;
  16105. }
  16106. else
  16107. {
  16108. isSuccess = ConfigurationStatus_Rejected;
  16109. }
  16110. }
  16111. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16112. {
  16113. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16114. {
  16115. check_ascii = value[0];
  16116. if( (check_ascii < 48) || (check_ascii > 57) )
  16117. {
  16118. isSuccess = ConfigurationStatus_Rejected;
  16119. }
  16120. else
  16121. {
  16122. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16123. isSuccess = ConfigurationStatus_Accepted;
  16124. }
  16125. }
  16126. else
  16127. {
  16128. isSuccess = ConfigurationStatus_Rejected;
  16129. }
  16130. }
  16131. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16132. {
  16133. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16134. {
  16135. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16136. isSuccess = ConfigurationStatus_Accepted;
  16137. }
  16138. else
  16139. {
  16140. isSuccess = ConfigurationStatus_Rejected;
  16141. }
  16142. }
  16143. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16144. {
  16145. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16146. {
  16147. check_ascii = value[0];
  16148. if( (check_ascii < 48) || (check_ascii > 57) )
  16149. {
  16150. isSuccess = ConfigurationStatus_Rejected;
  16151. }
  16152. else
  16153. {
  16154. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16155. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16156. isSuccess = ConfigurationStatus_Accepted;
  16157. }
  16158. }
  16159. else
  16160. {
  16161. isSuccess = ConfigurationStatus_Rejected;
  16162. }
  16163. }
  16164. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16165. {
  16166. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16167. {
  16168. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16169. isSuccess = ConfigurationStatus_Accepted;
  16170. }
  16171. else
  16172. {
  16173. isSuccess = ConfigurationStatus_Rejected;
  16174. }
  16175. }
  16176. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16177. {
  16178. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16179. {
  16180. check_ascii = value[0];
  16181. if( (check_ascii < 48) || (check_ascii > 57) )
  16182. {
  16183. isSuccess = ConfigurationStatus_Rejected;
  16184. }
  16185. else
  16186. {
  16187. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16188. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16189. isSuccess = ConfigurationStatus_Accepted;
  16190. }
  16191. }
  16192. else
  16193. {
  16194. isSuccess = ConfigurationStatus_Rejected;
  16195. }
  16196. }
  16197. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16198. {
  16199. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16200. {
  16201. check_ascii = value[0];
  16202. if( (check_ascii < 48) || (check_ascii > 57) )
  16203. {
  16204. isSuccess = ConfigurationStatus_Rejected;
  16205. }
  16206. else
  16207. {
  16208. if((atoi(value) == 0) || (atoi(value) >= 3))
  16209. {
  16210. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16211. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16212. isSuccess = ConfigurationStatus_Accepted;
  16213. }
  16214. else
  16215. {
  16216. isSuccess = ConfigurationStatus_Rejected;
  16217. }
  16218. }
  16219. }
  16220. else
  16221. {
  16222. isSuccess = ConfigurationStatus_Rejected;
  16223. }
  16224. }
  16225. if(strcmp(key, "MinimumStatusDuration") == 0)
  16226. {
  16227. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16228. {
  16229. check_ascii = value[0];
  16230. if( (check_ascii < 48) || (check_ascii > 57) )
  16231. {
  16232. isSuccess = ConfigurationStatus_Rejected;
  16233. }
  16234. else
  16235. {
  16236. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16237. {
  16238. isSuccess = ConfigurationStatus_Rejected;
  16239. }
  16240. else
  16241. {
  16242. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16243. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16244. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16245. isSuccess = ConfigurationStatus_Accepted;
  16246. }
  16247. }
  16248. }
  16249. else
  16250. {
  16251. isSuccess = ConfigurationStatus_Rejected;
  16252. }
  16253. }
  16254. if(strcmp(key, "NumberOfConnectors") == 0)
  16255. {
  16256. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].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. //Charger.ResetRetries = Integer.parseInt(value);
  16266. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16267. isSuccess = ConfigurationStatus_Accepted;
  16268. }
  16269. }
  16270. else
  16271. {
  16272. isSuccess = ConfigurationStatus_Rejected;
  16273. }
  16274. }
  16275. if(strcmp(key, "ResetRetries") == 0)
  16276. {
  16277. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16278. {
  16279. check_ascii = value[0];
  16280. if( (check_ascii < 48) || (check_ascii > 57) )
  16281. {
  16282. isSuccess = ConfigurationStatus_Rejected;
  16283. }
  16284. else
  16285. {
  16286. //Charger.ResetRetries = Integer.parseInt(value);
  16287. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16288. isSuccess = ConfigurationStatus_Accepted;
  16289. }
  16290. }
  16291. else
  16292. {
  16293. isSuccess = ConfigurationStatus_Rejected;
  16294. }
  16295. }
  16296. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16297. {
  16298. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16299. {
  16300. strcpy(str, (const char*)value);
  16301. for(int i = 0; str[i]; i++)
  16302. {
  16303. str[i] = tolower(str[i]);
  16304. }
  16305. if(strcmp(str, "notapplicable")== 0)
  16306. {
  16307. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16308. isSuccess = ConfigurationStatus_Accepted;
  16309. }
  16310. else if(strcmp(str, "unknown")== 0)
  16311. {
  16312. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16313. isSuccess = ConfigurationStatus_Accepted;
  16314. }
  16315. else if(strcmp(str, "rst")== 0)
  16316. {
  16317. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16318. isSuccess = ConfigurationStatus_Accepted;
  16319. }
  16320. else if(strcmp(str, "rts")== 0)
  16321. {
  16322. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16323. isSuccess = ConfigurationStatus_Accepted;
  16324. }
  16325. else if(strcmp(str, "srt")== 0)
  16326. {
  16327. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16328. isSuccess = ConfigurationStatus_Accepted;
  16329. }
  16330. else if(strcmp(str, "str")== 0)
  16331. {
  16332. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16333. isSuccess = ConfigurationStatus_Accepted;
  16334. }
  16335. else if(strcmp(str, "trs")== 0)
  16336. {
  16337. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16338. isSuccess = ConfigurationStatus_Accepted;
  16339. }
  16340. else if(strcmp(str, "tsr")== 0)
  16341. {
  16342. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16343. isSuccess = ConfigurationStatus_Accepted;
  16344. }
  16345. else
  16346. {
  16347. isSuccess = ConfigurationStatus_Rejected;
  16348. }
  16349. }
  16350. else
  16351. {
  16352. isSuccess = ConfigurationStatus_Rejected;
  16353. }
  16354. }
  16355. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16356. {
  16357. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16358. {
  16359. check_ascii = value[0];
  16360. if( (check_ascii < 48) || (check_ascii > 57) )
  16361. {
  16362. isSuccess = ConfigurationStatus_Rejected;
  16363. }
  16364. else
  16365. {
  16366. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16367. isSuccess = ConfigurationStatus_Accepted;
  16368. }
  16369. }
  16370. else
  16371. {
  16372. isSuccess = ConfigurationStatus_Rejected;
  16373. }
  16374. }
  16375. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16376. {
  16377. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16378. {
  16379. strcpy(str, (const char*)value);
  16380. for(int i = 0; str[i]; i++)
  16381. {
  16382. str[i] = tolower(str[i]);
  16383. }
  16384. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16385. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16386. isSuccess = ConfigurationStatus_Accepted;
  16387. }
  16388. else
  16389. {
  16390. isSuccess = ConfigurationStatus_Rejected;
  16391. }
  16392. }
  16393. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16394. {
  16395. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16396. {
  16397. strcpy(str, (const char*)value);
  16398. for(int i = 0; str[i]; i++)
  16399. {
  16400. str[i] = tolower(str[i]);
  16401. }
  16402. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16403. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16404. isSuccess = ConfigurationStatus_Accepted;
  16405. }
  16406. else
  16407. {
  16408. isSuccess = ConfigurationStatus_Rejected;
  16409. }
  16410. }
  16411. if(strcmp(key, "StopTxnAlignedData") == 0)
  16412. {
  16413. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16414. {
  16415. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16416. isSuccess = ConfigurationStatus_Accepted;
  16417. }
  16418. else
  16419. {
  16420. isSuccess = ConfigurationStatus_Rejected;
  16421. }
  16422. }
  16423. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16424. {
  16425. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16426. {
  16427. check_ascii = value[0];
  16428. if( (check_ascii < 48) || (check_ascii > 57) )
  16429. {
  16430. isSuccess = ConfigurationStatus_Rejected;
  16431. }
  16432. else
  16433. {
  16434. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16435. isSuccess = ConfigurationStatus_Accepted;
  16436. }
  16437. }
  16438. else
  16439. {
  16440. isSuccess = ConfigurationStatus_Rejected;
  16441. }
  16442. }
  16443. if(strcmp(key, "StopTxnSampledData") == 0)
  16444. {
  16445. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16446. {
  16447. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16448. isSuccess = ConfigurationStatus_Accepted;
  16449. }
  16450. else
  16451. {
  16452. isSuccess = ConfigurationStatus_Rejected;
  16453. }
  16454. }
  16455. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16456. {
  16457. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16458. {
  16459. check_ascii = value[0];
  16460. if( (check_ascii < 48) || (check_ascii > 57) )
  16461. {
  16462. isSuccess = ConfigurationStatus_Rejected;
  16463. }
  16464. else
  16465. {
  16466. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16467. isSuccess = ConfigurationStatus_Accepted;
  16468. }
  16469. }
  16470. else
  16471. {
  16472. isSuccess = ConfigurationStatus_Rejected;
  16473. }
  16474. }
  16475. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16476. {
  16477. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16478. {
  16479. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16480. isSuccess = ConfigurationStatus_Accepted;
  16481. }
  16482. else
  16483. {
  16484. isSuccess = ConfigurationStatus_Rejected;
  16485. }
  16486. }
  16487. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16488. {
  16489. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16490. {
  16491. check_ascii = value[0];
  16492. if( (check_ascii < 48) || (check_ascii > 57) )
  16493. {
  16494. isSuccess = ConfigurationStatus_Rejected;
  16495. }
  16496. else
  16497. {
  16498. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16499. isSuccess = ConfigurationStatus_Accepted;
  16500. }
  16501. }
  16502. else
  16503. {
  16504. isSuccess = ConfigurationStatus_Rejected;
  16505. }
  16506. }
  16507. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16508. {
  16509. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16510. {
  16511. check_ascii = value[0];
  16512. if( (check_ascii < 48) || (check_ascii > 57) )
  16513. {
  16514. isSuccess = ConfigurationStatus_Rejected;
  16515. }
  16516. else
  16517. {
  16518. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16519. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16520. TransactionMessageAttemptsValue = atoi(value);
  16521. isSuccess = ConfigurationStatus_Accepted;
  16522. }
  16523. }
  16524. else
  16525. {
  16526. isSuccess = ConfigurationStatus_Rejected;
  16527. }
  16528. }
  16529. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16530. {
  16531. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16532. {
  16533. check_ascii = value[0];
  16534. if( (check_ascii < 48) || (check_ascii > 57) )
  16535. {
  16536. isSuccess = ConfigurationStatus_Rejected;
  16537. }
  16538. else
  16539. {
  16540. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16541. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16542. TransactionMessageRetryIntervalValue = atoi(value);
  16543. isSuccess = ConfigurationStatus_Accepted;
  16544. }
  16545. }
  16546. else
  16547. {
  16548. isSuccess = ConfigurationStatus_Rejected;
  16549. }
  16550. }
  16551. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16552. {
  16553. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16554. {
  16555. strcpy(str, (const char*)value);
  16556. for(int i = 0; str[i]; i++)
  16557. {
  16558. str[i] = tolower(str[i]);
  16559. }
  16560. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16561. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16562. isSuccess = ConfigurationStatus_Accepted;
  16563. }
  16564. else
  16565. {
  16566. isSuccess = ConfigurationStatus_Rejected;
  16567. }
  16568. }
  16569. if(strcmp(key, "WebSocketPingInterval") == 0)
  16570. {
  16571. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].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. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16581. isSuccess = ConfigurationStatus_Accepted;
  16582. if((atoi(value) == 0) || (atoi(value) >= 10))
  16583. {
  16584. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16585. isSuccess = ConfigurationStatus_Accepted;
  16586. }
  16587. else
  16588. isSuccess = ConfigurationStatus_Rejected;
  16589. }
  16590. }
  16591. else
  16592. {
  16593. isSuccess = ConfigurationStatus_Rejected;
  16594. }
  16595. }
  16596. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16597. {
  16598. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16599. {
  16600. strcpy(str, (const char*)value);
  16601. for(int i = 0; str[i]; i++)
  16602. {
  16603. str[i] = tolower(str[i]);
  16604. }
  16605. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16606. isSuccess = ConfigurationStatus_Accepted;
  16607. }
  16608. else
  16609. {
  16610. isSuccess = ConfigurationStatus_Rejected;
  16611. }
  16612. }
  16613. if(strcmp(key, "AuthorizationKey") == 0)
  16614. {
  16615. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16616. {
  16617. strcpy(str, (const char*)value);
  16618. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16619. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16620. isSuccess = ConfigurationStatus_Accepted;
  16621. }
  16622. else
  16623. {
  16624. isSuccess = ConfigurationStatus_Rejected;
  16625. }
  16626. }
  16627. if(strcmp(key, "SecurityProfile") == 0)
  16628. {
  16629. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16630. {
  16631. check_ascii = value[0];
  16632. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16633. {
  16634. isSuccess = ConfigurationStatus_Rejected;
  16635. }
  16636. else if(check_ascii == 0x33)
  16637. {
  16638. isSuccess = NotSupported;
  16639. }
  16640. else
  16641. {
  16642. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16643. {
  16644. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16645. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16646. isSuccess = ConfigurationStatus_Accepted;
  16647. }
  16648. else
  16649. isSuccess = ConfigurationStatus_Rejected;
  16650. }
  16651. }
  16652. else
  16653. {
  16654. isSuccess = ConfigurationStatus_Rejected;
  16655. }
  16656. }
  16657. if(strcmp(key, "DefaultPrice") == 0)
  16658. {
  16659. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16660. {
  16661. strcpy(str, (const char*)value);
  16662. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16663. isSuccess = ConfigurationStatus_Accepted;
  16664. }
  16665. else
  16666. {
  16667. isSuccess = ConfigurationStatus_Rejected;
  16668. }
  16669. }
  16670. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16671. {
  16672. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16673. {
  16674. strcpy(str, (const char*)value);
  16675. for(int i = 0; str[i]; i++)
  16676. {
  16677. str[i] = tolower(str[i]);
  16678. }
  16679. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16680. isSuccess = ConfigurationStatus_Accepted;
  16681. }
  16682. else
  16683. {
  16684. isSuccess = ConfigurationStatus_Rejected;
  16685. }
  16686. }
  16687. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16688. {
  16689. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16690. {
  16691. strcpy(str, (const char*)value);
  16692. for(int i = 0; str[i]; i++)
  16693. {
  16694. str[i] = tolower(str[i]);
  16695. }
  16696. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16697. isSuccess = ConfigurationStatus_Accepted;
  16698. }
  16699. else
  16700. {
  16701. isSuccess = ConfigurationStatus_Rejected;
  16702. }
  16703. }
  16704. if(strcmp(key, "SystemUptimeSec") == 0)
  16705. {
  16706. isSuccess = NotSupported;
  16707. }
  16708. if(strcmp(key, "FreeVend") == 0)
  16709. {
  16710. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].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. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16718. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].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, "FreeVendIdtag") == 0)
  16727. {
  16728. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16729. {
  16730. strcpy(str, (const char*)value);
  16731. if(strlen(str) <= 20)
  16732. {
  16733. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16734. isSuccess = ConfigurationStatus_Accepted;
  16735. }
  16736. else
  16737. {
  16738. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16739. isSuccess = ConfigurationStatus_Rejected;
  16740. }
  16741. }
  16742. else
  16743. {
  16744. isSuccess = ConfigurationStatus_Rejected;
  16745. }
  16746. }
  16747. if(strcmp(key, "OcppServer") == 0)
  16748. {
  16749. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16750. {
  16751. strcpy(str, (const char*)value);
  16752. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16753. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16754. isSuccess = ConfigurationStatus_Accepted;
  16755. }
  16756. else
  16757. {
  16758. isSuccess = ConfigurationStatus_Rejected;
  16759. }
  16760. }
  16761. if(strcmp(key, "MaintainServer") == 0)
  16762. {
  16763. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16764. {
  16765. strcpy(str, (const char*)value);
  16766. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16767. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16768. isSuccess = ConfigurationStatus_Accepted;
  16769. }
  16770. else
  16771. {
  16772. isSuccess = ConfigurationStatus_Rejected;
  16773. }
  16774. }
  16775. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16776. {
  16777. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16778. {
  16779. strcpy(str, (const char*)value);
  16780. for(int i = 0; str[i]; i++)
  16781. {
  16782. str[i] = tolower(str[i]);
  16783. }
  16784. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16785. isSuccess = ConfigurationStatus_Accepted;
  16786. }
  16787. else
  16788. {
  16789. isSuccess = ConfigurationStatus_Rejected;
  16790. }
  16791. }
  16792. if(strcmp(key, "StatusNotificationInterval") == 0)
  16793. {
  16794. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16795. {
  16796. check_ascii = value[0];
  16797. if( (check_ascii < 48) || (check_ascii > 57) )
  16798. {
  16799. isSuccess = ConfigurationStatus_Rejected;
  16800. }
  16801. else
  16802. {
  16803. if((atoi(value) == 0) || (atoi(value) >= 10))
  16804. {
  16805. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16806. isSuccess = ConfigurationStatus_Accepted;
  16807. }
  16808. else
  16809. isSuccess = ConfigurationStatus_Rejected;
  16810. }
  16811. }
  16812. else
  16813. {
  16814. isSuccess = ConfigurationStatus_Rejected;
  16815. }
  16816. }
  16817. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  16818. {
  16819. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16820. {
  16821. check_ascii = value[0];
  16822. if( (check_ascii < 48) || (check_ascii > 57) )
  16823. {
  16824. isSuccess = ConfigurationStatus_Rejected;
  16825. }
  16826. else
  16827. {
  16828. if(atoi(value) >= 0)
  16829. {
  16830. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value) );
  16831. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  16832. isSuccess = ConfigurationStatus_Accepted;
  16833. }
  16834. else
  16835. isSuccess = ConfigurationStatus_Rejected;
  16836. }
  16837. }
  16838. else
  16839. {
  16840. isSuccess = ConfigurationStatus_Rejected;
  16841. }
  16842. }
  16843. if(strcmp(key, "PowerSharingServerIP") == 0)
  16844. {
  16845. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16846. {
  16847. strcpy(str, (const char*)value);
  16848. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  16849. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  16850. isSuccess = ConfigurationStatus_Accepted;
  16851. }
  16852. else
  16853. {
  16854. isSuccess = ConfigurationStatus_Rejected;
  16855. }
  16856. }
  16857. if(strcmp(key, "EVCCID_PREFIX") == 0)
  16858. {
  16859. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16860. {
  16861. strcpy(str, (const char*)value);
  16862. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  16863. isSuccess = ConfigurationStatus_Accepted;
  16864. }
  16865. else
  16866. {
  16867. isSuccess = ConfigurationStatus_Rejected;
  16868. }
  16869. }
  16870. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  16871. {
  16872. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  16873. {
  16874. if(atoi(value) > modelnameInfo.ratedPower)
  16875. {
  16876. isSuccess = ConfigurationStatus_Rejected;
  16877. }
  16878. else{
  16879. strcpy(str, (const char*)value);
  16880. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  16881. isSuccess = ConfigurationStatus_Accepted;
  16882. }
  16883. }
  16884. else
  16885. {
  16886. isSuccess = ConfigurationStatus_Rejected;
  16887. }
  16888. }
  16889. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  16890. {
  16891. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  16892. {
  16893. if((atoi(value) != 0) && (atoi(value) < 5))
  16894. {
  16895. isSuccess = ConfigurationStatus_Rejected;
  16896. }
  16897. else{
  16898. strcpy(str, (const char*)value);
  16899. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  16900. isSuccess = ConfigurationStatus_Accepted;
  16901. }
  16902. }
  16903. else
  16904. {
  16905. isSuccess = ConfigurationStatus_Rejected;
  16906. }
  16907. }
  16908. #if 0
  16909. //For OCPP Test Case
  16910. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16911. {
  16912. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16913. {
  16914. strcpy(str, (const char*)value);
  16915. for(int i = 0; str[i]; i++)
  16916. {
  16917. str[i] = tolower(str[i]);
  16918. }
  16919. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16920. isSuccess = ConfigurationStatus_Accepted;
  16921. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16922. }
  16923. else
  16924. {
  16925. isSuccess = ConfigurationStatus_Rejected;
  16926. }
  16927. }
  16928. #endif
  16929. #if 1
  16930. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16931. {
  16932. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16933. {
  16934. strcpy(str, (const char*)value);
  16935. for(int i = 0; str[i]; i++)
  16936. {
  16937. str[i] = tolower(str[i]);
  16938. }
  16939. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16940. isSuccess = ConfigurationStatus_Accepted;
  16941. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16942. }
  16943. else
  16944. {
  16945. isSuccess = ConfigurationStatus_Rejected;
  16946. }
  16947. }
  16948. #endif
  16949. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16950. {
  16951. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16952. {
  16953. check_ascii = value[0];
  16954. if( (check_ascii < 48) || (check_ascii > 57) )
  16955. {
  16956. isSuccess = ConfigurationStatus_Rejected;
  16957. }
  16958. else
  16959. {
  16960. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16961. isSuccess = ConfigurationStatus_Accepted;
  16962. }
  16963. }
  16964. else
  16965. {
  16966. isSuccess = ConfigurationStatus_Rejected;
  16967. }
  16968. }
  16969. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16970. {
  16971. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16972. {
  16973. check_ascii = value[0];
  16974. if( (check_ascii < 48) || (check_ascii > 57) )
  16975. {
  16976. isSuccess = ConfigurationStatus_Rejected;
  16977. }
  16978. else
  16979. {
  16980. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16981. isSuccess = ConfigurationStatus_Accepted;
  16982. }
  16983. }
  16984. else
  16985. {
  16986. isSuccess = ConfigurationStatus_Rejected;
  16987. }
  16988. }
  16989. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16990. {
  16991. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16992. {
  16993. strcpy(str, (const char*)value);
  16994. for(int i = 0; str[i]; i++)
  16995. {
  16996. str[i] = tolower(str[i]);
  16997. }
  16998. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16999. isSuccess = ConfigurationStatus_Accepted;
  17000. }
  17001. else
  17002. {
  17003. isSuccess = ConfigurationStatus_Rejected;
  17004. }
  17005. }
  17006. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17007. {
  17008. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17009. {
  17010. check_ascii = value[0];
  17011. if( (check_ascii < 48) || (check_ascii > 57) )
  17012. {
  17013. isSuccess = ConfigurationStatus_Rejected;
  17014. }
  17015. else
  17016. {
  17017. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17018. isSuccess = ConfigurationStatus_Accepted;
  17019. }
  17020. }
  17021. else
  17022. {
  17023. isSuccess = ConfigurationStatus_Rejected;
  17024. }
  17025. }
  17026. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17027. {
  17028. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17029. {
  17030. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17031. isSuccess = ConfigurationStatus_Accepted;
  17032. }
  17033. else
  17034. {
  17035. isSuccess = ConfigurationStatus_Rejected;
  17036. }
  17037. }
  17038. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17039. {
  17040. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17041. {
  17042. check_ascii = value[0];
  17043. if( (check_ascii < 48) || (check_ascii > 57) )
  17044. {
  17045. isSuccess = ConfigurationStatus_Rejected;
  17046. }
  17047. else
  17048. {
  17049. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17050. isSuccess = ConfigurationStatus_Accepted;
  17051. }
  17052. }
  17053. else
  17054. {
  17055. isSuccess = ConfigurationStatus_Rejected;
  17056. }
  17057. }
  17058. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17059. {
  17060. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17061. {
  17062. strcpy(str, (const char*)value);
  17063. for(int i = 0; str[i]; i++)
  17064. {
  17065. str[i] = tolower(str[i]);
  17066. }
  17067. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17068. isSuccess = ConfigurationStatus_Accepted;
  17069. }
  17070. else
  17071. {
  17072. isSuccess = ConfigurationStatus_Rejected;
  17073. }
  17074. }
  17075. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17076. {
  17077. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17078. {
  17079. check_ascii = value[0];
  17080. if( (check_ascii < 48) || (check_ascii > 57) )
  17081. {
  17082. isSuccess = ConfigurationStatus_Rejected;
  17083. }
  17084. else
  17085. {
  17086. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17087. isSuccess = ConfigurationStatus_Accepted;
  17088. }
  17089. }
  17090. else
  17091. {
  17092. isSuccess = ConfigurationStatus_Rejected;
  17093. }
  17094. }
  17095. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17096. return isSuccess;
  17097. }
  17098. int TransactionMessageAttemptsGet(void)
  17099. {
  17100. return TransactionMessageAttemptsValue;
  17101. }
  17102. int FirstHeartBeatResponse(void)
  17103. {
  17104. return FirstHeartBeat;
  17105. }
  17106. int TransactionMessageRetryIntervalGet(void)
  17107. {
  17108. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17109. }
  17110. int ReadHttpStatus(int sock)
  17111. {
  17112. //char c;
  17113. char buff[1024]="",*ptr=buff+1;
  17114. int bytes_received, status;
  17115. DEBUG_INFO("Begin Response ..\n");
  17116. while((bytes_received = recv(sock, ptr, 1, 0))){
  17117. if(bytes_received==-1){
  17118. perror("ReadHttpStatus");
  17119. exit(1);
  17120. }
  17121. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17122. ptr++;
  17123. }
  17124. *ptr=0;
  17125. ptr=buff+1;
  17126. sscanf(ptr,"%*s %d ", &status);
  17127. DEBUG_INFO("%s\n",ptr);
  17128. DEBUG_INFO("status=%d\n",status);
  17129. DEBUG_INFO("End Response ..\n");
  17130. return (bytes_received>0)?status:0;
  17131. }
  17132. //the only filed that it parsed is 'Content-Length'
  17133. int ParseHeader(int sock)
  17134. {
  17135. //char c;
  17136. char buff[1024]="",*ptr=buff+4;
  17137. int bytes_received;
  17138. DEBUG_INFO("Begin HEADER ..\n");
  17139. while((bytes_received = recv(sock, ptr, 1, 0))){
  17140. if(bytes_received==-1){
  17141. perror("Parse Header");
  17142. exit(1);
  17143. }
  17144. if(
  17145. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17146. (ptr[-1]=='\r') && (*ptr=='\n' )
  17147. ) break;
  17148. ptr++;
  17149. }
  17150. *ptr=0;
  17151. ptr=buff+4;
  17152. //printf("%s",ptr);
  17153. if(bytes_received){
  17154. ptr=strstr(ptr,"Content-Length:");
  17155. if(ptr){
  17156. sscanf(ptr,"%*s %d",&bytes_received);
  17157. }else
  17158. bytes_received=-1; //unknown size
  17159. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17160. }
  17161. DEBUG_INFO("End HEADER ..\n");
  17162. return bytes_received ;
  17163. }
  17164. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17165. {
  17166. int result = TRUE;
  17167. char rmFileCmd[100]={0};
  17168. char FilePath[100]={0};
  17169. char ftpbuf[200];
  17170. int systemresult;
  17171. sprintf(FilePath,"/mnt/%s",filename);
  17172. system("ping 8.8.8.8 &");
  17173. if((access(FilePath,F_OK))!=-1)
  17174. {
  17175. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17176. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17177. system(rmFileCmd);
  17178. }
  17179. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17180. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17181. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17182. systemresult = system(ftpbuf);
  17183. if(systemresult != 0)
  17184. {
  17185. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17186. result = FALSE;
  17187. }
  17188. system("pkill ping");
  17189. return result;
  17190. }
  17191. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  17192. {
  17193. int result = TRUE;
  17194. char rmFileCmd[100]={0};
  17195. char FilePath[100]={0};
  17196. char ftpbuf[200];
  17197. int systemresult;
  17198. sprintf(FilePath,"/mnt/%s",filename);
  17199. system("ping 8.8.8.8 &");
  17200. if((access(FilePath,F_OK))!=-1)
  17201. {
  17202. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17203. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17204. system(rmFileCmd);
  17205. }
  17206. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17207. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  17208. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17209. systemresult = system(ftpbuf);
  17210. if(systemresult != 0)
  17211. {
  17212. DEBUG_WARN("scp error!\n");
  17213. result = FALSE;
  17214. }
  17215. system("pkill ping");
  17216. return result;
  17217. }
  17218. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17219. {
  17220. int result = TRUE;
  17221. char rmFileCmd[100]={0};
  17222. char FilePath[100]={0};
  17223. char ftpbuf[200];
  17224. int systemresult;
  17225. sprintf(FilePath,"/mnt/%s",filename);
  17226. system("ping 8.8.8.8 &");
  17227. if((access(FilePath,F_OK))!=-1)
  17228. {
  17229. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17230. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17231. system(rmFileCmd);
  17232. }
  17233. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17234. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17235. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17236. systemresult = system(ftpbuf);
  17237. if(systemresult != 0)
  17238. {
  17239. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17240. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17241. systemresult = system(ftpbuf);
  17242. if(systemresult != 0)
  17243. {
  17244. DEBUG_WARN("FTP download fail!\n");
  17245. result = FALSE;
  17246. }
  17247. }
  17248. system("pkill ping");
  17249. return result;
  17250. }
  17251. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17252. {
  17253. char rmFileCmd[100]={0};
  17254. char FilePath[100]={0};
  17255. char buf[512];
  17256. int systemresult = 0;
  17257. //DEBUG_INFO("filename=%s\n",filename);
  17258. //DEBUG_INFO("url=%s\n",url);
  17259. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17260. if((access(FilePath,F_OK))!=-1)
  17261. {
  17262. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17263. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17264. system(rmFileCmd);
  17265. }
  17266. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17267. if(fp == NULL)
  17268. {
  17269. DEBUG_INFO("log is NULL\n");
  17270. return FALSE;
  17271. }
  17272. else
  17273. {
  17274. fprintf(fp, "%s\n", url);
  17275. fprintf(fp, "%s\n", filename);
  17276. fclose(fp);
  17277. }
  17278. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17279. if(phpFP == NULL)
  17280. {
  17281. DEBUG_INFO("PHP upload fail.\n");
  17282. return FALSE;
  17283. }
  17284. else
  17285. {
  17286. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17287. {
  17288. if(strstr(buf, "result") != NULL)
  17289. {
  17290. sscanf(buf, "result: %d", &systemresult);
  17291. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17292. }
  17293. }
  17294. pclose(phpFP);
  17295. }
  17296. if(systemresult != 1)
  17297. {
  17298. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17299. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17300. if(phpFP == NULL)
  17301. {
  17302. DEBUG_WARN("PHP PUT upload fail.\n");
  17303. return FALSE;
  17304. }
  17305. else
  17306. {
  17307. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17308. {
  17309. if(strstr(buf, "result") != NULL)
  17310. {
  17311. sscanf(buf, "result: %d", &systemresult);
  17312. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17313. }
  17314. }
  17315. pclose(phpFP);
  17316. }
  17317. }
  17318. if(systemresult != 1)
  17319. {
  17320. DEBUG_WARN("PHP PUT upload fail.\n");
  17321. return FALSE;
  17322. }
  17323. return TRUE;
  17324. }
  17325. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17326. {
  17327. int result = FALSE;
  17328. char ftpbuf[200];
  17329. int systemresult;
  17330. /*
  17331. // Domaind name transfer to IP address
  17332. struct hostent* server;
  17333. char *IPbuffer;
  17334. server = gethostbyname(location);
  17335. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17336. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17337. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17338. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17339. systemresult = system(ftpbuf);
  17340. if(systemresult != 0)
  17341. {
  17342. DEBUG_INFO("ftpput error!\n");
  17343. }
  17344. else
  17345. {
  17346. result = TRUE;
  17347. DEBUG_INFO("ftpput OK!\n");
  17348. }
  17349. return result;
  17350. }
  17351. int GetOcppServerURL()
  17352. {
  17353. int result = FALSE;
  17354. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17355. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17356. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17357. struct yuarel url;
  17358. char urlStr[512];
  17359. // OCPPPH only
  17360. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  17361. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  17362. {
  17363. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  17364. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17365. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17366. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  17367. if(yuarel_parse(&url, urlStr) != -1)
  17368. {
  17369. sprintf(OcppProtocol, "%s", url.scheme);
  17370. sprintf(OcppHost, "%s", url.host);
  17371. if(url.path == NULL)
  17372. OcppTempPath[0] = '\0';
  17373. else
  17374. sprintf(OcppTempPath, "%s", url.path);
  17375. if(url.port == 0)
  17376. {
  17377. if(strcmp(OcppProtocol, "wss") == 0)
  17378. OcppPort = 443;
  17379. else
  17380. OcppPort = 80;
  17381. }
  17382. else
  17383. OcppPort = url.port;
  17384. result = TRUE;
  17385. }
  17386. }
  17387. else
  17388. {
  17389. strcpy(OcppHost,"");
  17390. }
  17391. return result;
  17392. }
  17393. int GetOcppPath()
  17394. {
  17395. int result = FALSE;
  17396. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  17397. {
  17398. if(OcppTempPath == NULL)
  17399. {
  17400. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  17401. }
  17402. else
  17403. {
  17404. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  17405. }
  17406. result = TRUE;
  17407. goto End;
  17408. }
  17409. else
  17410. {
  17411. strcpy(OcppPath,"");
  17412. }
  17413. End:
  17414. return result;
  17415. }
  17416. int GetOcppPort()
  17417. {
  17418. return OcppPort;
  17419. }
  17420. int GetOcppConnStatus(void)
  17421. {
  17422. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17423. }
  17424. void SetOcppConnStatus(uint8_t status)
  17425. {
  17426. ShmOCPP16DataPH->OcppConnStatus = status;
  17427. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17428. }
  17429. int GetHeartBeatWithNOResponse(void)
  17430. {
  17431. return HeartBeatWithNOResponse;
  17432. }
  17433. void SetHeartBeatWithNOResponse(void)
  17434. {
  17435. HeartBeatWithNOResponse = 0;
  17436. }
  17437. void GetStartTransactionIdTag(int gun_index)
  17438. {
  17439. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17440. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17441. }
  17442. int GetStartTransactionId(int gun_index)
  17443. {
  17444. return ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17445. }
  17446. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17447. {
  17448. char ch;
  17449. FILE *fptr1;
  17450. int temptransactionId;
  17451. char str[100]={0};
  17452. temptransactionId = 0;
  17453. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17454. {
  17455. DEBUG_INFO("IdTag is empty.\n");
  17456. return temptransactionId;
  17457. }
  17458. /*------ Read the file ----------------*/
  17459. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17460. if (!fptr1)
  17461. {
  17462. DEBUG_INFO("QueueTransactionId file open error.\n");
  17463. //printf(" File not found or unable to open the input file!!\n");
  17464. return temptransactionId;
  17465. }
  17466. ch=fgetc(fptr1);
  17467. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17468. rewind(fptr1);
  17469. if(ch!=EOF)
  17470. {
  17471. // printf("%c",ch);
  17472. while (fgets(str, 100, fptr1) != NULL)
  17473. {
  17474. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17475. if(str[0]=='\0')
  17476. {
  17477. break;
  17478. }
  17479. char *revbuf[8] = {0}; // Variable store string split
  17480. int num = 0;// Quantity after string split
  17481. DEBUG_INFO("Transaction queue data= %s\n", str);
  17482. splitstring(str,",",revbuf,&num); // String split
  17483. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17484. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17485. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17486. DEBUG_INFO("------------------------------\n");
  17487. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17488. {
  17489. if(isStopTransaction)
  17490. {
  17491. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17492. {
  17493. temptransactionId = atoi(revbuf[2]);
  17494. //break;
  17495. }
  17496. }
  17497. else
  17498. {
  17499. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17500. {
  17501. temptransactionId = atoi(revbuf[2]);
  17502. //break;
  17503. }
  17504. }
  17505. }
  17506. }
  17507. }
  17508. else
  17509. DEBUG_INFO("EOF\n");
  17510. fclose(fptr1);
  17511. /*------- End of reading ---------------*/
  17512. return temptransactionId;
  17513. }
  17514. void SetTransactionIdZero(int transactionId)
  17515. {
  17516. char ch;
  17517. FILE *fptr1, *fptr2;
  17518. int temptransactionId = 0;
  17519. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17520. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17521. if (!fptr1)
  17522. {
  17523. //printf(" File not found or unable to open the input file!!\n");
  17524. return ;
  17525. }
  17526. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17527. if (!fptr2)
  17528. {
  17529. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17530. fclose(fptr1);
  17531. return ;
  17532. }
  17533. ch=fgetc(fptr1);
  17534. rewind(fptr1);
  17535. if(ch!=EOF)
  17536. {
  17537. // copy all contents to the temporary file except the specific line
  17538. while (fgets(str, 100, fptr1) != NULL)
  17539. {
  17540. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17541. if(str[0]=='\0')
  17542. {
  17543. break;
  17544. }
  17545. char *revbuf[8] = {0};
  17546. int num = 0;
  17547. strcpy(strtemp, str);
  17548. splitstring(str,",",revbuf,&num);
  17549. if(revbuf[2][0] != '\0')
  17550. {
  17551. temptransactionId = atoi(revbuf[2]);
  17552. if(transactionId != temptransactionId)
  17553. {
  17554. fprintf(fptr2, "%s\n", strtemp);
  17555. }
  17556. }
  17557. }
  17558. }
  17559. fclose(fptr1);
  17560. fclose(fptr2);
  17561. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17562. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17563. /*------ Read the file ----------------*/
  17564. }
  17565. int InternetDisconnect(void)
  17566. {
  17567. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17568. }
  17569. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17570. void storeTempStopTransaction(int gun_index)
  17571. {
  17572. char guid[37]={0};
  17573. int tempIndex = 0;
  17574. char TempStopTransaction[256];
  17575. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17576. DEBUG_INFO("storeTempStopTransaction...\n");
  17577. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17578. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17579. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17580. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17581. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17582. {
  17583. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17584. {
  17585. tempIndex = ((gun_index==2) ? 1: 0);
  17586. }
  17587. else
  17588. {
  17589. tempIndex = gun_index;
  17590. }
  17591. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17592. {
  17593. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17594. {
  17595. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17596. }
  17597. }// END OF CHAdeMO_QUANTITY
  17598. }
  17599. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17600. {
  17601. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17602. {
  17603. tempIndex = ((gun_index==2) ? 1: 0);
  17604. }
  17605. else
  17606. {
  17607. tempIndex = gun_index;
  17608. }
  17609. for (int index = 0; index < CCS_QUANTITY; index++)
  17610. {
  17611. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17612. {
  17613. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17614. }
  17615. }// END OF CCS_QUANTITY
  17616. }
  17617. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17618. {
  17619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17620. {
  17621. tempIndex = ((gun_index==2) ? 1: 0);
  17622. }
  17623. else
  17624. {
  17625. tempIndex = gun_index;
  17626. }
  17627. for (int index = 0; index < GB_QUANTITY; index++)
  17628. {
  17629. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17630. {
  17631. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17632. }
  17633. }// END OF GB_QUANTITY
  17634. }
  17635. else if(gunType[gun_index] == GUN_TYPE_DO)
  17636. {
  17637. tempIndex = gun_index;
  17638. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17639. {
  17640. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17641. {
  17642. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17643. }
  17644. }
  17645. }
  17646. else
  17647. {
  17648. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17649. {
  17650. tempIndex = 2;
  17651. }
  17652. else
  17653. {
  17654. tempIndex = gun_index;
  17655. }
  17656. for (int index = 0; index < AC_QUANTITY; index++)
  17657. {
  17658. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17659. {
  17660. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17661. }
  17662. }// END OF AC_QUANTITY
  17663. }
  17664. //Stop Transaction Time
  17665. struct timeval tmnow;
  17666. struct tm *tm;
  17667. char buf[28];//, usec_buf[6];
  17668. gettimeofday(&tmnow, NULL);
  17669. time_t t;
  17670. t = time(NULL);
  17671. /*UTC time and date*/
  17672. tm = gmtime(&t);
  17673. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17674. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17675. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17676. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17677. random_uuid(guid);
  17678. /***********************************transactionData******************************************************/
  17679. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17681. //=================================
  17682. //1. Transaction_Begin
  17683. //=================================
  17684. //============================== Energy.Active.Import.Interval ===========================================
  17685. //=================================
  17686. //2. Transaction_End
  17687. //=================================
  17688. //2.1====================================== Current.Import L1 ==============================================
  17689. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17690. {
  17691. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17692. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17693. {
  17694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17695. {
  17696. tempIndex = ((gun_index==2) ? 1: 0);
  17697. }
  17698. else
  17699. {
  17700. tempIndex = gun_index;
  17701. }
  17702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17703. {
  17704. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17705. {
  17706. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17707. }
  17708. }// End of for CHAdeMO_QUANTITY
  17709. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17710. }
  17711. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17712. {
  17713. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17714. {
  17715. tempIndex = ((gun_index==2) ? 1: 0);
  17716. }
  17717. else
  17718. {
  17719. tempIndex = gun_index;
  17720. }
  17721. for (int index = 0; index < CCS_QUANTITY; index++)
  17722. {
  17723. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17724. {
  17725. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17726. }
  17727. }// End of for CCS_QUANTITY
  17728. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17729. }
  17730. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17731. {
  17732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17733. {
  17734. tempIndex = ((gun_index==2) ? 1: 0);
  17735. }
  17736. else
  17737. {
  17738. tempIndex = gun_index;
  17739. }
  17740. for (int index = 0; index < GB_QUANTITY; index++)
  17741. {
  17742. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17743. {
  17744. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17745. }
  17746. }// End of for GB_QUANTITY
  17747. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17748. }
  17749. else if(gunType[gun_index] == GUN_TYPE_DO)
  17750. {
  17751. tempIndex = gun_index;
  17752. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17753. {
  17754. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17755. {
  17756. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17757. }
  17758. }
  17759. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17760. }
  17761. else
  17762. {
  17763. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17764. {
  17765. tempIndex = 2;
  17766. }
  17767. else
  17768. {
  17769. tempIndex = gun_index;
  17770. }
  17771. for (int index = 0; index < AC_QUANTITY; index++)
  17772. {
  17773. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17774. {
  17775. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17776. }
  17777. }// End of for AC_QUANTITY
  17778. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17779. }
  17780. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17781. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17783. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17784. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17785. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17786. }
  17787. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17788. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17789. {
  17790. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17791. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17792. {
  17793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17794. {
  17795. tempIndex = ((gun_index==2) ? 1: 0);
  17796. }
  17797. else
  17798. {
  17799. tempIndex = gun_index;
  17800. }
  17801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17802. {
  17803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17804. {
  17805. 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
  17806. }
  17807. }// END OF CHAdeMO_QUANTITY
  17808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17809. }
  17810. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17811. {
  17812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17813. {
  17814. tempIndex = ((gun_index==2) ? 1: 0);
  17815. }
  17816. else
  17817. {
  17818. tempIndex = gun_index;
  17819. }
  17820. for (int index = 0; index < CCS_QUANTITY; index++)
  17821. {
  17822. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17823. {
  17824. 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
  17825. }
  17826. }// END OF CCS_QUANTITY
  17827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17828. }
  17829. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17830. {
  17831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17832. {
  17833. tempIndex = ((gun_index==2) ? 1: 0);
  17834. }
  17835. else
  17836. {
  17837. tempIndex = gun_index;
  17838. }
  17839. for (int index = 0; index < GB_QUANTITY; index++)
  17840. {
  17841. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17842. {
  17843. 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
  17844. }
  17845. }// END OF GB_QUANTITY
  17846. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17847. }
  17848. else if(gunType[gun_index] == GUN_TYPE_DO)
  17849. {
  17850. tempIndex = gun_index;
  17851. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17852. {
  17853. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17854. {
  17855. 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
  17856. }
  17857. }
  17858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17859. }
  17860. else
  17861. {
  17862. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17863. {
  17864. tempIndex = 2;
  17865. }
  17866. else
  17867. {
  17868. tempIndex = gun_index;
  17869. }
  17870. for (int index = 0; index < AC_QUANTITY; index++)
  17871. {
  17872. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17873. {
  17874. 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
  17875. }
  17876. }// END OF AC_QUANTITY
  17877. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17878. }
  17879. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17880. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17881. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17882. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17883. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17884. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17885. }
  17886. //2.3====================================== Power.Active.Import =========================================
  17887. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17888. {
  17889. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17890. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17891. {
  17892. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17893. {
  17894. tempIndex = ((gun_index==2) ? 1: 0);
  17895. }
  17896. else
  17897. {
  17898. tempIndex = gun_index;
  17899. }
  17900. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17901. {
  17902. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17903. {
  17904. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17905. }
  17906. } // End for CHAdeMO_QUANTITY
  17907. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17908. }
  17909. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17910. {
  17911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17912. {
  17913. tempIndex = ((gun_index==2) ? 1: 0);
  17914. }
  17915. else
  17916. {
  17917. tempIndex = gun_index;
  17918. }
  17919. for (int index = 0; index < CCS_QUANTITY; index++)
  17920. {
  17921. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17922. {
  17923. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17924. }
  17925. } // END for CCS_QUANTITY
  17926. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17927. }
  17928. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17929. {
  17930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17931. {
  17932. tempIndex = ((gun_index==2) ? 1: 0);
  17933. }
  17934. else
  17935. {
  17936. tempIndex = gun_index;
  17937. }
  17938. for (int index = 0; index < GB_QUANTITY; index++)
  17939. {
  17940. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17941. {
  17942. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17943. }
  17944. }// END for GB_QUANTITY
  17945. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17946. }
  17947. else if(gunType[gun_index] == GUN_TYPE_DO)
  17948. {
  17949. tempIndex = gun_index;
  17950. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17951. {
  17952. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17953. {
  17954. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17955. }
  17956. }
  17957. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17958. }
  17959. else
  17960. {
  17961. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17962. {
  17963. tempIndex = 2;
  17964. }
  17965. else
  17966. {
  17967. tempIndex = gun_index;
  17968. }
  17969. for (int index = 0; index < AC_QUANTITY; index++)
  17970. {
  17971. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17972. {
  17973. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17974. }
  17975. } // END for AC_QUANTITY
  17976. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17977. }
  17978. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17979. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17980. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17981. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17982. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17983. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17984. }
  17985. //2.4====================================== Voltage L1 ====================================================
  17986. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17987. {
  17988. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17989. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17990. {
  17991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17992. {
  17993. tempIndex = ((gun_index==2) ? 1: 0);
  17994. }
  17995. else
  17996. {
  17997. tempIndex = gun_index;
  17998. }
  17999. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18000. {
  18001. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18002. {
  18003. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18004. }
  18005. } // END OF FOR CHAdeMO_QUANTITY
  18006. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18007. }
  18008. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18009. {
  18010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18011. {
  18012. tempIndex = ((gun_index==2) ? 1: 0);
  18013. }
  18014. else
  18015. {
  18016. tempIndex = gun_index;
  18017. }
  18018. for (int index = 0; index < CCS_QUANTITY; index++)
  18019. {
  18020. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18021. {
  18022. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18023. }
  18024. } // END OF FOR CCS_QUANTITY
  18025. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18026. }
  18027. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18028. {
  18029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18030. {
  18031. tempIndex = ((gun_index==2) ? 1: 0);
  18032. }
  18033. else
  18034. {
  18035. tempIndex = gun_index;
  18036. }
  18037. for (int index = 0; index < GB_QUANTITY; index++)
  18038. {
  18039. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18040. {
  18041. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18042. }
  18043. } // END OF FOR GB_QUANTITY
  18044. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18045. }
  18046. else if(gunType[gun_index] == GUN_TYPE_DO)
  18047. {
  18048. tempIndex = gun_index;
  18049. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18050. {
  18051. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18052. {
  18053. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18054. }
  18055. }
  18056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18057. }
  18058. else
  18059. {
  18060. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18061. {
  18062. tempIndex = 2;
  18063. }
  18064. else
  18065. {
  18066. tempIndex = gun_index;
  18067. }
  18068. for (int index = 0; index < AC_QUANTITY; index++)
  18069. {
  18070. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18071. {
  18072. 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
  18073. }
  18074. } // END OF FOR AC_QUANTITY
  18075. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18076. }
  18077. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18078. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18079. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18080. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18081. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18082. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18083. }
  18084. //2.5============================================== End SoC =========================================================
  18085. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18086. {
  18087. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18088. 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))
  18089. {
  18090. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18091. {
  18092. tempIndex = ((gun_index==2) ? 1: 0);
  18093. }
  18094. else
  18095. {
  18096. tempIndex = gun_index;
  18097. }
  18098. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18099. {
  18100. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18101. {
  18102. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18103. {
  18104. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18105. }
  18106. }
  18107. }
  18108. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18109. {
  18110. for (int index = 0; index < CCS_QUANTITY; index++)
  18111. {
  18112. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18113. {
  18114. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18115. }
  18116. }
  18117. }
  18118. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18119. {
  18120. for (int index = 0; index < GB_QUANTITY; index++)
  18121. {
  18122. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18123. {
  18124. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18125. }
  18126. }
  18127. }
  18128. else if(gunType[gun_index] == GUN_TYPE_DO)
  18129. {
  18130. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18131. {
  18132. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18133. {
  18134. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18135. }
  18136. }
  18137. }
  18138. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18139. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18140. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18141. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18142. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18143. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18144. } // END FOR DC CASE
  18145. }
  18146. //2.6====================================== Current.Import L2 ==============================================
  18147. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18148. {
  18149. // AC 3 phase L2 current
  18150. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18151. {
  18152. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18153. {
  18154. tempIndex = 2;
  18155. }
  18156. else
  18157. {
  18158. tempIndex = gun_index;
  18159. }
  18160. for (int index = 0; index < AC_QUANTITY; index++)
  18161. {
  18162. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18163. {
  18164. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18165. }
  18166. }// End of for AC_QUANTITY
  18167. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18168. }
  18169. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18170. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18171. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18172. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18173. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18174. }
  18175. //2.7====================================== Current.Import L3 ==============================================
  18176. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18177. {
  18178. // AC 3 phase L3 current
  18179. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18180. {
  18181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18182. {
  18183. tempIndex = 2;
  18184. }
  18185. else
  18186. {
  18187. tempIndex = gun_index;
  18188. }
  18189. for (int index = 0; index < AC_QUANTITY; index++)
  18190. {
  18191. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18192. {
  18193. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18194. }
  18195. }// End of for AC_QUANTITY
  18196. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18197. }
  18198. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18199. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18200. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18201. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18202. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18203. }
  18204. //2.9====================================== Voltage L2 ====================================================
  18205. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18206. {
  18207. // AC 3 phase L2 volatge
  18208. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18209. {
  18210. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18211. {
  18212. tempIndex = 2;
  18213. }
  18214. else
  18215. {
  18216. tempIndex = gun_index;
  18217. }
  18218. for (int index = 0; index < AC_QUANTITY; index++)
  18219. {
  18220. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18221. {
  18222. 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
  18223. }
  18224. } // END OF FOR AC_QUANTITY
  18225. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18226. }
  18227. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18228. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18229. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18230. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18231. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18232. }
  18233. //2.10====================================== Voltage L3 ====================================================
  18234. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18235. {
  18236. // AC 3 phase L3 volatge
  18237. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18238. {
  18239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18240. {
  18241. tempIndex = 2;
  18242. }
  18243. else
  18244. {
  18245. tempIndex = gun_index;
  18246. }
  18247. for (int index = 0; index < AC_QUANTITY; index++)
  18248. {
  18249. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18250. {
  18251. 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
  18252. }
  18253. } // END OF FOR AC_QUANTITY
  18254. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18255. }
  18256. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18257. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18258. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18259. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18260. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18261. }
  18262. //====================== Start SoC ================================
  18263. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18264. {
  18265. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18266. 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))
  18267. {
  18268. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18269. {
  18270. tempIndex = ((gun_index==2) ? 1: 0);
  18271. }
  18272. else
  18273. {
  18274. tempIndex = gun_index;
  18275. }
  18276. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18277. {
  18278. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18279. {
  18280. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18281. {
  18282. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18283. }
  18284. }
  18285. }
  18286. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18287. {
  18288. for (int index = 0; index < CCS_QUANTITY; index++)
  18289. {
  18290. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18291. {
  18292. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18293. }
  18294. }
  18295. }
  18296. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18297. {
  18298. for (int index = 0; index < GB_QUANTITY; index++)
  18299. {
  18300. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18301. {
  18302. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18303. }
  18304. }
  18305. }
  18306. else if(gunType[gun_index] == GUN_TYPE_DO)
  18307. {
  18308. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18309. {
  18310. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18311. {
  18312. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18313. }
  18314. }
  18315. }
  18316. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18317. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18318. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18319. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18320. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18321. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18322. } // END FOR DC CASE
  18323. }
  18324. //======================================== Message create ==============================================
  18325. json_object *StopTransaction = json_object_new_object();
  18326. json_object *transactionDatas = json_object_new_array();
  18327. json_object *sampledValues = json_object_new_array();
  18328. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  18329. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  18330. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  18331. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  18332. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  18333. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18334. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  18335. {
  18336. json_object *transactionData = json_object_new_object();
  18337. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18338. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18339. {
  18340. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18341. {
  18342. json_object *sampledValue = json_object_new_object();
  18343. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18344. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18345. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18346. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18347. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18348. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18349. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18350. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18351. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18352. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18353. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18354. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18355. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18356. json_object_array_add(sampledValues, sampledValue);
  18357. }
  18358. }
  18359. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18360. json_object_array_add(transactionDatas, transactionData);
  18361. }
  18362. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18363. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18364. ,MESSAGE_TYPE_CALL
  18365. ,guid
  18366. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18367. json_object_put(StopTransaction);
  18368. // Check File "TempStopTransaction" Exist
  18369. if((access(TempStopTransaction,F_OK))!=-1)
  18370. {
  18371. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18372. fclose(fopen(TempStopTransaction, "w"));
  18373. }
  18374. else
  18375. {
  18376. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18377. FILE *log = fopen(TempStopTransaction, "w+");
  18378. if(log == NULL)
  18379. {
  18380. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18381. return ;
  18382. }
  18383. else
  18384. {
  18385. fclose(log);
  18386. }
  18387. }
  18388. //Add TempStopTransaction | Update TempStopTransaction
  18389. // open file for writing
  18390. FILE *outfile;
  18391. outfile = fopen (TempStopTransaction, "a");
  18392. //DEBUG_INFO("data = %s\n", queuedata);
  18393. fputs(queuedata, outfile);
  18394. fputs("\n", outfile);
  18395. fclose (outfile);
  18396. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18397. }
  18398. void checkTempStopTransaction(int gun_index)
  18399. {
  18400. FILE *fptr1;
  18401. char ch;
  18402. char str[QUEUE_MESSAGE_LENGTH]={0};
  18403. char guid[37]={0};
  18404. char tempdata[65]={0};
  18405. char connectorStr[2]={0};
  18406. char TempStopTransaction[256];
  18407. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18408. fptr1 = fopen(TempStopTransaction, "r");
  18409. //TempStopTransaction格式: 槍號,StopTransaction封包
  18410. if (!fptr1)
  18411. {
  18412. //printf(" File not found or unable to open the input file!!\n");
  18413. return ;
  18414. }
  18415. ch=fgetc(fptr1);
  18416. //printf(" Now the content of the file %s is : \n",fname);
  18417. rewind(fptr1);
  18418. if(ch!=EOF)
  18419. {
  18420. // copy all contents to the temporary file except the specific line
  18421. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18422. {
  18423. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18424. if(str[0]=='\0')
  18425. {
  18426. break;
  18427. }
  18428. //TempStopTransaction格式: 槍號,StopTransaction封包
  18429. strncpy(connectorStr, str, 1);
  18430. if(atoi(connectorStr) != (gun_index+1))
  18431. {
  18432. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18433. fclose(fptr1);
  18434. return ;
  18435. }
  18436. //random_uuid(guid);
  18437. strncpy(guid, str+6, 36); //copy guid
  18438. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18439. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18440. {
  18441. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18442. }
  18443. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18444. OCPP_insert_transaction_msg(NO, str);
  18445. memset(str,0,ARRAY_SIZE(str));
  18446. }
  18447. }
  18448. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18449. fclose(fptr1);
  18450. remove(TempStopTransaction); // remove the original file
  18451. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18452. }
  18453. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18454. {
  18455. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18456. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18457. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18458. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18459. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18460. }
  18461. int GetWebSocketPingInterval(void)
  18462. {
  18463. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18464. }
  18465. int GetServerSign(void)
  18466. {
  18467. return server_sign;
  18468. }
  18469. uint8_t GetOcppSecurityProfile()
  18470. {
  18471. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18472. }
  18473. void GetOcppChargerBoxId(uint8_t *data)
  18474. {
  18475. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18476. }
  18477. void GetOcppSecurityPassword(uint8_t *data)
  18478. {
  18479. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18480. }
  18481. void SetOcppVersion(uint8_t *version)
  18482. {
  18483. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18484. DEBUG_INFO("ocpp version: %s\n", version);
  18485. if(strstr((char*)version, "ocpp1.6") != NULL)
  18486. {
  18487. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18488. }
  18489. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18490. {
  18491. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18492. system("pkill OcppBackend");
  18493. }
  18494. }
  18495. void SetServerSign(int value)
  18496. {
  18497. server_sign = value;
  18498. }
  18499. int GetBootNotificationInterval(void)
  18500. {
  18501. return BootNotificationInterval;
  18502. }
  18503. int GetInternetConn(void)
  18504. {
  18505. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18506. }
  18507. int GetBackendConnectionTimeout(void)
  18508. {
  18509. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18510. }
  18511. int isConnectorInitMode(int gun_index)
  18512. {
  18513. int tempIndex = 0;
  18514. int result = TRUE;
  18515. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18516. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18517. {
  18518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18519. {
  18520. tempIndex = ((gun_index==2) ? 1: 0);
  18521. }
  18522. else
  18523. {
  18524. tempIndex = gun_index;
  18525. }
  18526. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18527. {
  18528. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18529. {
  18530. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18531. } //end of the same index
  18532. }//end of for CHAdeMO_QUANTITY
  18533. }
  18534. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18535. {
  18536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18537. {
  18538. tempIndex = ((gun_index==2) ? 1: 0);
  18539. }
  18540. else
  18541. {
  18542. tempIndex = gun_index;
  18543. }
  18544. for (int index = 0; index < CCS_QUANTITY; index++)
  18545. {
  18546. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18547. {
  18548. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18549. } //end of the same index
  18550. } // end of for CCS_QUANTITY
  18551. }
  18552. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18553. {
  18554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18555. {
  18556. tempIndex = ((gun_index==2) ? 1: 0);
  18557. }
  18558. else
  18559. {
  18560. tempIndex = gun_index;
  18561. }
  18562. for (int index = 0; index < GB_QUANTITY; index++)
  18563. {
  18564. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18565. {
  18566. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18567. } //end of the same index
  18568. } // end of for GB_QUANTITY
  18569. }
  18570. else if(gunType[gun_index] == GUN_TYPE_DO)
  18571. {
  18572. tempIndex = gun_index;
  18573. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18574. {
  18575. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18576. {
  18577. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18578. } //end of the same index
  18579. }
  18580. }
  18581. else
  18582. {
  18583. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18584. {
  18585. tempIndex = 2;
  18586. }
  18587. else
  18588. {
  18589. tempIndex = gun_index;
  18590. }
  18591. for (int index = 0; index < AC_QUANTITY; index++)
  18592. {
  18593. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18594. {
  18595. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18596. }//end of the same index
  18597. }//end of for AC_QUANTITY
  18598. }
  18599. return result;
  18600. }
  18601. void refreshProcDogTimer()
  18602. {
  18603. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18604. }
  18605. void InitialSystemValue(void)
  18606. {
  18607. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18608. locallistVersion=0;
  18609. BootNotificationInterval = 0;
  18610. authorizeRetryTimes = 0;
  18611. GunStatusInterval = 10;
  18612. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18613. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18614. //Hear Beat
  18615. HeartBeatWithNOResponse = 0;
  18616. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18617. FirstHeartBeat = 0;
  18618. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18619. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18620. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18621. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18622. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18623. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18624. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18625. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18626. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18627. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18628. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18629. //Status && ConnectorPlugIn Setting
  18630. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18631. {
  18632. ChademoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18633. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18634. }
  18635. for (int index = 0; index < CCS_QUANTITY; index++)
  18636. {
  18637. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18638. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18639. }
  18640. for (int index = 0; index < GB_QUANTITY; index++)
  18641. {
  18642. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18643. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18644. }
  18645. for (int index = 0; index < AC_QUANTITY; index++)
  18646. {
  18647. AcPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18648. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18649. }
  18650. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18651. {
  18652. DoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18653. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18654. }
  18655. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18656. {
  18657. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18658. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18659. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18660. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18661. //memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18662. memset(&ShmOCPP16DataPH->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16DataPH->StatusNotification[gun_index].Status));
  18663. }
  18664. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18665. refreshStartTimer(&clientTime.Heartbeat);
  18666. sleep(1);
  18667. }
  18668. void LWS_Send(char *str)
  18669. {
  18670. //=====================================================
  18671. // Check InternetConn 0: disconnected, 1: connected
  18672. //====================================================
  18673. if(GetOcppConnStatus() == 0)
  18674. {
  18675. DEBUG_INFO("offline now !!!\n");
  18676. return;
  18677. }
  18678. // Only disable isWebsocketSendable operation initiated by charger
  18679. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18680. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18681. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18682. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18683. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18684. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18685. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18686. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18687. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18688. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18689. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18690. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18691. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18692. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18693. {
  18694. isWebsocketSendable = 0;
  18695. }
  18696. pthread_mutex_lock(&lock_send);
  18697. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18698. sprintf((char *)SendBuffer, "%s", str);
  18699. SendBufLen = strlen(str);
  18700. pthread_mutex_unlock(&lock_send);
  18701. lws_callback_on_writable(wsi_client);
  18702. //lws_service(context, 0);
  18703. //sleep(1);
  18704. }
  18705. void LWS_SendNow(char *str)
  18706. {
  18707. //=====================================================
  18708. // Check InternetConn 0: disconnected, 1: connected
  18709. //====================================================
  18710. if(GetOcppConnStatus() == 0)
  18711. {
  18712. DEBUG_INFO("offline now !!!\n");
  18713. return;
  18714. }
  18715. // Only disable isWebsocketSendable operation initiated by charger
  18716. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18717. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18718. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18719. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18720. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18721. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18722. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18723. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18724. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18725. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18726. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18727. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18728. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18729. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18730. {
  18731. isWebsocketSendable = 0;
  18732. }
  18733. pthread_mutex_lock(&lock_send);
  18734. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18735. sprintf((char *)SendBuffer, "%s", str);
  18736. SendBufLen = strlen(str);
  18737. pthread_mutex_unlock(&lock_send);
  18738. lws_callback_on_writable(wsi_client);
  18739. lws_service(context, 0);
  18740. //sleep(1);
  18741. }