MessageHandler.c 941 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423
  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. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  3545. ) // 'D' means DC
  3546. {
  3547. // DO series
  3548. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3549. {
  3550. gunTotalNumber += 1;
  3551. gunType[gun_index] = GUN_TYPE_DO;
  3552. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3553. {
  3554. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3555. {
  3556. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3557. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3558. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3559. }
  3560. }
  3561. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3562. {
  3563. case Gun_Type_Chademo:
  3564. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3565. break;
  3566. case Gun_Type_CCS_2:
  3567. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3568. break;
  3569. case Gun_Type_GB:
  3570. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3571. break;
  3572. case Gun_Type_AC:
  3573. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3574. break;
  3575. default:
  3576. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3577. break;
  3578. }
  3579. }
  3580. }
  3581. else
  3582. {
  3583. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3584. {
  3585. gunTotalNumber += 1;
  3586. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3587. {
  3588. case Gun_Type_Chademo:
  3589. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3590. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3591. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  3592. {
  3593. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  3594. {
  3595. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3596. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3597. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  3598. }
  3599. }
  3600. break;
  3601. case Gun_Type_CCS_2:
  3602. gunType[gun_index] = GUN_TYPE_CCS;
  3603. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3604. for (int index = 0; index < CCS_QUANTITY; index++)
  3605. {
  3606. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  3607. {
  3608. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3609. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3610. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  3611. }
  3612. }
  3613. break;
  3614. case Gun_Type_GB:
  3615. gunType[gun_index] = GUN_TYPE_GBT;
  3616. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3617. for (int index = 0; index < GB_QUANTITY; index++)
  3618. {
  3619. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  3620. {
  3621. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3622. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3623. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  3624. }
  3625. }
  3626. break;
  3627. case Gun_Type_AC:
  3628. gunType[gun_index] = GUN_TYPE_AC;
  3629. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3630. for (int index = 0; index < AC_QUANTITY; index++)
  3631. {
  3632. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  3633. {
  3634. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3635. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3636. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  3637. }
  3638. }
  3639. break;
  3640. default:
  3641. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3642. break;
  3643. }
  3644. }
  3645. }
  3646. }
  3647. else
  3648. {
  3649. DEBUG_ERROR("Model name parsing fail.\n");
  3650. result = FAIL;
  3651. }
  3652. if(result != PASS)sleep(5);
  3653. return result;
  3654. }
  3655. void checkRemoteStart(uint8_t connectorIdInt)
  3656. {
  3657. uint8_t tempIndex;
  3658. int result = PASS;
  3659. char cmdBuf[512];
  3660. //check Transaction active
  3661. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3662. {
  3663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3664. {
  3665. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3666. }
  3667. else
  3668. {
  3669. tempIndex = connectorIdInt -1;
  3670. }
  3671. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3672. {
  3673. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3674. {
  3675. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3676. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3677. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3678. {
  3679. //Reserved
  3680. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3681. }
  3682. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3683. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3684. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3685. {
  3686. //Reserved
  3687. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3688. result = FAIL;
  3689. goto end;
  3690. }
  3691. else
  3692. {
  3693. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3694. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3695. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3696. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3697. {
  3698. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3699. result = FAIL;
  3700. goto end;
  3701. }
  3702. }//END FOR ELSE
  3703. }
  3704. }// END FOR CHAdeMO_QUANTITY
  3705. }
  3706. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3707. {
  3708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3709. {
  3710. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3711. }
  3712. else
  3713. {
  3714. tempIndex = connectorIdInt -1;
  3715. }
  3716. for (int index = 0; index < CCS_QUANTITY; index++)
  3717. {
  3718. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3719. {
  3720. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3721. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3722. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3723. {
  3724. //Reserved
  3725. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3726. }
  3727. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3728. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3729. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3730. {
  3731. //Reserved
  3732. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3733. result = FAIL;
  3734. goto end;
  3735. }
  3736. else
  3737. {
  3738. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3739. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3740. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3741. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3742. {
  3743. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3744. result = FAIL;
  3745. goto end;
  3746. }
  3747. }// END FOR ELSE
  3748. }
  3749. }// END FOR CCS_QUANTITY
  3750. }
  3751. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3752. {
  3753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3754. {
  3755. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3756. }
  3757. else
  3758. {
  3759. tempIndex = connectorIdInt -1;
  3760. }
  3761. for (int index = 0; index < GB_QUANTITY; index++)
  3762. {
  3763. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3764. {
  3765. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3766. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3767. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3768. {
  3769. //Reserved
  3770. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3771. }
  3772. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3773. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3774. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3775. {
  3776. //Reserved
  3777. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3778. result = FAIL;
  3779. goto end;
  3780. }
  3781. else
  3782. {
  3783. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3784. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3785. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3786. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3787. {
  3788. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3789. result = FAIL;
  3790. goto end;
  3791. }
  3792. }// END FOR ELSE
  3793. }
  3794. } // END FOR GB_QUANTITY
  3795. }
  3796. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3797. {
  3798. tempIndex = connectorIdInt -1;
  3799. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3800. {
  3801. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3802. {
  3803. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3804. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3805. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3806. {
  3807. //Reserved
  3808. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3809. }
  3810. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3811. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3812. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3813. {
  3814. //Reserved
  3815. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3816. result = FAIL;
  3817. goto end;
  3818. }
  3819. else
  3820. {
  3821. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3822. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3823. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3824. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3825. {
  3826. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3827. result = FAIL;
  3828. goto end;
  3829. }
  3830. }// END FOR ELSE
  3831. }
  3832. } // END FOR GB_QUANTITY
  3833. }
  3834. else
  3835. {
  3836. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3837. {
  3838. tempIndex = 2;
  3839. }
  3840. else
  3841. {
  3842. tempIndex = connectorIdInt -1;
  3843. }
  3844. for (int index = 0; index < AC_QUANTITY; index++)
  3845. {
  3846. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3847. {
  3848. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3849. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3850. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3851. {
  3852. //Reserved
  3853. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3854. }
  3855. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3856. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3857. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3858. {
  3859. //Reserved
  3860. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3861. result = FAIL;
  3862. goto end;
  3863. }
  3864. else
  3865. {
  3866. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3867. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3868. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3869. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3870. {
  3871. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3872. result = FAIL;
  3873. goto end;
  3874. }
  3875. }//END FOR ELSE
  3876. }
  3877. }// END FOR AC_QUANTITY
  3878. }
  3879. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3880. {
  3881. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3882. {
  3883. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3884. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3885. {
  3886. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3887. system(cmdBuf);
  3888. }
  3889. }
  3890. else
  3891. {
  3892. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3893. result = FAIL;
  3894. }
  3895. }
  3896. end:
  3897. if(result == PASS)
  3898. {
  3899. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3900. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3901. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3902. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3903. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3904. }
  3905. }
  3906. void CheckSystemValue(void)
  3907. {
  3908. char filenmae[100]={0};
  3909. char str[100]={0};
  3910. int tempIndex = 0;
  3911. //===============================
  3912. // send Heartbeat
  3913. //===============================
  3914. if((server_sign == TRUE) && (HeartBeatWaitTime > 0) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3915. {
  3916. //parameter for test
  3917. sendHeartbeatRequest(0);
  3918. //==============================================
  3919. // Reset Waiting Time
  3920. //==============================================
  3921. HeartBeatWithNOResponse += 2;
  3922. }
  3923. //===============================
  3924. // Credit deduct report
  3925. //===============================
  3926. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3927. {
  3928. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3929. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3930. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3931. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3932. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3933. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3934. }
  3935. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3936. {
  3937. OCPP_query_deduct_info();
  3938. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3939. }
  3940. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3941. {
  3942. // ClockAlign MeterValue
  3943. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3944. {
  3945. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3946. {
  3947. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3948. {
  3949. tempIndex = ((gun_index==2) ? 1: 0);
  3950. }
  3951. else
  3952. {
  3953. tempIndex = gun_index;
  3954. }
  3955. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3956. {
  3957. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3958. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3959. {
  3960. reqClockAlignMeter[gun_index] = 1;
  3961. }
  3962. }// End for CHAdeMO
  3963. }
  3964. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3965. {
  3966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3967. {
  3968. tempIndex = ((gun_index==2) ? 1: 0);
  3969. }
  3970. else
  3971. {
  3972. tempIndex = gun_index;
  3973. }
  3974. for (int index = 0; index < CCS_QUANTITY; index++)
  3975. {
  3976. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3977. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3978. {
  3979. reqClockAlignMeter[gun_index] = 1;
  3980. }
  3981. } // End for CCS
  3982. }
  3983. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3984. {
  3985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3986. {
  3987. tempIndex = ((gun_index==2) ? 1: 0);
  3988. }
  3989. else
  3990. {
  3991. tempIndex = gun_index;
  3992. }
  3993. for (int index = 0; index < GB_QUANTITY; index++)
  3994. {
  3995. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3996. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3997. {
  3998. reqClockAlignMeter[gun_index] = 1;
  3999. }
  4000. }// End for GB
  4001. }
  4002. else if(gunType[gun_index] == GUN_TYPE_DO)
  4003. {
  4004. tempIndex = gun_index;
  4005. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4006. {
  4007. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4008. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4009. {
  4010. reqClockAlignMeter[gun_index] = 1;
  4011. }
  4012. }
  4013. }
  4014. else
  4015. {
  4016. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4017. {
  4018. tempIndex = 2;
  4019. }
  4020. else
  4021. {
  4022. tempIndex = gun_index;
  4023. }
  4024. for (int index = 0; index < AC_QUANTITY; index++)
  4025. {
  4026. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4027. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4028. {
  4029. reqClockAlignMeter[gun_index] = 1;
  4030. }
  4031. }//End for AC
  4032. }
  4033. }
  4034. }
  4035. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4036. {
  4037. //==========================================
  4038. // Check remote start without connector id
  4039. //==========================================
  4040. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  4041. {
  4042. int connectorIdInt = -1;
  4043. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4044. {
  4045. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4046. {
  4047. connectorIdInt = (gun_index+1);
  4048. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4049. checkRemoteStart(connectorIdInt);
  4050. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4051. break;
  4052. }
  4053. }
  4054. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4055. {
  4056. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4057. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4058. }
  4059. }
  4060. //==========================================
  4061. // csu trigger DataTransferReq
  4062. //==========================================
  4063. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4064. {
  4065. sendDataTransferRequest(gun_index);
  4066. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4067. }
  4068. //===============================
  4069. // CSU Trigger Authorize Request
  4070. //===============================
  4071. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4072. {
  4073. sendAuthorizeRequest(0);
  4074. authorizeRetryTimes = authorizeRetryTimes + 1;
  4075. if(authorizeRetryTimes < 3)
  4076. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4077. }
  4078. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4079. {
  4080. authorizeRetryTimes = 0;
  4081. SetOcppConnStatus(FALSE);
  4082. server_sign = FALSE;
  4083. }
  4084. 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))
  4085. {
  4086. sendAuthorizeRequest(0);
  4087. }
  4088. //==============================================
  4089. // Charger start transaction
  4090. //==============================================
  4091. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4092. {
  4093. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4094. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4095. sendStartTransactionRequest(gun_index);
  4096. refreshStartTimer(&clientTime.StartTransaction);
  4097. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4098. //storeTempStopTransaction(gun_index);
  4099. }
  4100. //==============================================
  4101. // Charger stop transaction
  4102. //==============================================
  4103. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4104. {
  4105. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4106. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4107. sendStopTransactionRequest(gun_index);
  4108. refreshStartTimer(&clientTime.StopTransaction);
  4109. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4110. }
  4111. //==============================================
  4112. // Charger status report
  4113. //==============================================
  4114. //--- Check Mode Change ---//
  4115. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4116. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4117. {
  4118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4119. {
  4120. tempIndex = ((gun_index==2) ? 1: 0);
  4121. }
  4122. else
  4123. {
  4124. tempIndex = gun_index;
  4125. }
  4126. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4127. {
  4128. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4129. {
  4130. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4131. {
  4132. // Sent unplug message for California pricing logic
  4133. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4134. {
  4135. uint8_t ts[36];
  4136. getNowDatetime(ts);
  4137. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4138. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4139. if(strcmp((char*)dmsVersion, "2.0")==0)
  4140. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4141. else
  4142. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4143. sendUnplugByDataTransferRequest(gun_index);
  4144. interLock.isSentUnplug[gun_index] = 1;
  4145. }
  4146. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4147. {
  4148. interLock.isSentUnplug[gun_index] = 0;
  4149. }
  4150. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4151. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4152. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4153. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4154. {
  4155. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4156. if((access(filenmae,F_OK))!=-1)
  4157. {
  4158. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4159. sprintf(str,"rm -f %s",filenmae);
  4160. system(str);
  4161. }
  4162. }
  4163. }
  4164. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4165. #if 1 // for TempStopTransaction
  4166. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4167. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4168. {
  4169. checkTempStopTransaction(gun_index);
  4170. }
  4171. #endif
  4172. }
  4173. }
  4174. }
  4175. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4176. {
  4177. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4178. {
  4179. tempIndex = ((gun_index==2) ? 1: 0);
  4180. }
  4181. else
  4182. {
  4183. tempIndex = gun_index;
  4184. }
  4185. for (int index = 0; index < CCS_QUANTITY; index++)
  4186. {
  4187. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4188. {
  4189. 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]*/ )
  4190. {
  4191. // Sent unplug message for California pricing logic
  4192. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4193. {
  4194. uint8_t ts[36];
  4195. getNowDatetime(ts);
  4196. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4197. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4198. if(strcmp((char*)dmsVersion, "2.0")==0)
  4199. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4200. else
  4201. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4202. sendUnplugByDataTransferRequest(gun_index);
  4203. interLock.isSentUnplug[gun_index] = 1;
  4204. }
  4205. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4206. {
  4207. interLock.isSentUnplug[gun_index] = 0;
  4208. }
  4209. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4210. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4211. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4212. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4213. {
  4214. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4215. if((access(filenmae,F_OK))!=-1)
  4216. {
  4217. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4218. sprintf(str,"rm -f %s",filenmae);
  4219. system(str);
  4220. }
  4221. }
  4222. }
  4223. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4224. #if 1 // for TempStopTransaction
  4225. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4226. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4227. {
  4228. checkTempStopTransaction(gun_index);
  4229. }
  4230. #endif
  4231. }
  4232. }
  4233. }
  4234. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4235. {
  4236. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4237. {
  4238. tempIndex = ((gun_index==2) ? 1: 0);
  4239. }
  4240. else
  4241. {
  4242. tempIndex = gun_index;
  4243. }
  4244. for (int index = 0; index < GB_QUANTITY; index++)
  4245. {
  4246. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4247. {
  4248. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4249. {
  4250. // Sent unplug message for California pricing logic
  4251. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4252. {
  4253. uint8_t ts[36];
  4254. getNowDatetime(ts);
  4255. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4256. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4257. if(strcmp((char*)dmsVersion, "2.0")==0)
  4258. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4259. else
  4260. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4261. sendUnplugByDataTransferRequest(gun_index);
  4262. interLock.isSentUnplug[gun_index] = 1;
  4263. }
  4264. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4265. {
  4266. interLock.isSentUnplug[gun_index] = 0;
  4267. }
  4268. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4269. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4270. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4271. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4272. {
  4273. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4274. if((access(filenmae,F_OK))!=-1)
  4275. {
  4276. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4277. sprintf(str,"rm -f %s",filenmae);
  4278. system(str);
  4279. }
  4280. }
  4281. }
  4282. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4283. #if 1 // for TempStopTransaction
  4284. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4285. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4286. {
  4287. checkTempStopTransaction(gun_index);
  4288. }
  4289. #endif
  4290. }
  4291. }
  4292. }
  4293. else if(gunType[gun_index] == GUN_TYPE_DO)
  4294. {
  4295. tempIndex = gun_index;
  4296. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4297. {
  4298. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4299. {
  4300. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4301. {
  4302. // Sent unplug message for California pricing logic
  4303. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4304. {
  4305. uint8_t ts[36];
  4306. getNowDatetime(ts);
  4307. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4308. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4309. if(strcmp((char*)dmsVersion, "2.0")==0)
  4310. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4311. else
  4312. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4313. sendUnplugByDataTransferRequest(gun_index);
  4314. interLock.isSentUnplug[gun_index] = 1;
  4315. }
  4316. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4317. {
  4318. interLock.isSentUnplug[gun_index] = 0;
  4319. }
  4320. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4321. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4322. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4323. 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
  4324. {
  4325. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4326. if((access(filenmae,F_OK))!=-1)
  4327. {
  4328. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4329. sprintf(str,"rm -f %s",filenmae);
  4330. system(str);
  4331. }
  4332. }
  4333. }
  4334. 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);
  4335. #if 1 // for TempStopTransaction
  4336. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4337. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4338. {
  4339. checkTempStopTransaction(gun_index);
  4340. }
  4341. #endif
  4342. }
  4343. }
  4344. }
  4345. else
  4346. {
  4347. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4348. {
  4349. tempIndex = 2;
  4350. }
  4351. else
  4352. {
  4353. tempIndex = gun_index;
  4354. }
  4355. for (int index = 0; index < AC_QUANTITY; index++)
  4356. {
  4357. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4358. {
  4359. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4360. {
  4361. // Sent unplug message for California pricing logic
  4362. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4363. {
  4364. uint8_t ts[36];
  4365. getNowDatetime(ts);
  4366. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4367. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4368. if(strcmp((char*)dmsVersion, "2.0")==0)
  4369. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4370. else
  4371. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4372. sendUnplugByDataTransferRequest(gun_index);
  4373. interLock.isSentUnplug[gun_index] = 1;
  4374. }
  4375. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4376. {
  4377. interLock.isSentUnplug[gun_index] = 0;
  4378. }
  4379. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4380. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4381. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4382. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4383. {
  4384. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4385. if((access(filenmae,F_OK))!=-1)
  4386. {
  4387. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4388. sprintf(str,"rm -f %s",filenmae);
  4389. system(str);
  4390. }
  4391. }
  4392. }
  4393. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4394. #if 1 // for TempStopTransaction
  4395. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4396. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4397. {
  4398. checkTempStopTransaction(gun_index);
  4399. }
  4400. #endif
  4401. }
  4402. }// END
  4403. }
  4404. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4405. (
  4406. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4407. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4408. )
  4409. )
  4410. {
  4411. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4412. sendStatusNotificationRequest(gun_index);
  4413. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4414. }
  4415. //==============================================
  4416. // TCCI reader status report
  4417. //==============================================
  4418. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4419. {
  4420. reportReaderStatus(gun_index);
  4421. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4422. }
  4423. //==============================================
  4424. // CSU Trigger or timer timeout refresh Smart Charging Profile
  4425. //==============================================
  4426. if((ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  4427. ((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))))
  4428. {
  4429. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4430. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4431. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  4432. }
  4433. //==============================================
  4434. // Meter report
  4435. //==============================================
  4436. // Trigger MeterValue
  4437. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4438. {
  4439. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4440. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4441. }
  4442. // Clock-aligned Meter value
  4443. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4444. {
  4445. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4446. reqClockAlignMeter[gun_index] = 0;
  4447. }
  4448. // Sample period MeterValue
  4449. 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))))
  4450. {
  4451. //check Transaction active
  4452. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4453. {
  4454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4455. {
  4456. tempIndex = ((gun_index==2) ? 1: 0);
  4457. }
  4458. else
  4459. {
  4460. tempIndex = gun_index;
  4461. }
  4462. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4463. {
  4464. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4465. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4466. {
  4467. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4468. {
  4469. reqSampleMeter[gun_index] = 1;
  4470. }
  4471. }
  4472. }// End for CHAdeMO
  4473. }
  4474. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4475. {
  4476. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4477. {
  4478. tempIndex = ((gun_index==2) ? 1: 0);
  4479. }
  4480. else
  4481. {
  4482. tempIndex = gun_index;
  4483. }
  4484. for (int index = 0; index < CCS_QUANTITY; index++)
  4485. {
  4486. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4487. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4488. {
  4489. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4490. {
  4491. reqSampleMeter[gun_index] = 1;
  4492. }
  4493. }
  4494. } // End for CCS
  4495. }
  4496. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4497. {
  4498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4499. {
  4500. tempIndex = ((gun_index==2) ? 1: 0);
  4501. }
  4502. else
  4503. {
  4504. tempIndex = gun_index;
  4505. }
  4506. for (int index = 0; index < GB_QUANTITY; index++)
  4507. {
  4508. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4509. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4510. {
  4511. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4512. {
  4513. reqSampleMeter[gun_index] = 1;
  4514. }
  4515. }
  4516. }// End for GB
  4517. }
  4518. else if(gunType[gun_index] == GUN_TYPE_DO)
  4519. {
  4520. tempIndex = gun_index;
  4521. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4522. {
  4523. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4524. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4525. {
  4526. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4527. {
  4528. reqSampleMeter[gun_index] = 1;
  4529. }
  4530. }
  4531. }
  4532. }
  4533. else
  4534. {
  4535. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4536. {
  4537. tempIndex = 2;
  4538. }
  4539. else
  4540. {
  4541. tempIndex = gun_index;
  4542. }
  4543. for (int index = 0; index < AC_QUANTITY; index++)
  4544. {
  4545. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4546. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4547. {
  4548. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4549. {
  4550. reqSampleMeter[gun_index] = 1;
  4551. }
  4552. }
  4553. }//End for AC
  4554. }
  4555. if(reqSampleMeter[gun_index] == 1)
  4556. {
  4557. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4558. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4559. //storeTempStopTransaction(gun_index);
  4560. reqSampleMeter[gun_index] = 0;
  4561. }
  4562. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4563. }
  4564. //==============================================
  4565. // Check Connector reserved
  4566. //==============================================
  4567. //===============================
  4568. // Check if Reserve is expired
  4569. //===============================
  4570. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4571. {
  4572. double diff_t;
  4573. struct tm tp;
  4574. // current time
  4575. time_t t = time(NULL);
  4576. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4577. tp.tm_isdst = -1;
  4578. time_t utc = mktime(&tp);
  4579. diff_t = difftime(utc, t);
  4580. if(diff_t <= 0)
  4581. {
  4582. DEBUG_INFO("reserve expired.\n");
  4583. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4584. }
  4585. }//END OF Check if Reserve is expired
  4586. //==========================================
  4587. // csu trigger FirmwareStatusNotificationReq
  4588. //==========================================
  4589. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4590. {
  4591. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4592. }
  4593. //==========================================
  4594. // csu trigger DiagnosticsStatusNotificationReq
  4595. //==========================================
  4596. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4597. {
  4598. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4599. }
  4600. //==========================================
  4601. // csu trigger CancelReservationConf
  4602. //==========================================
  4603. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4604. {
  4605. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4606. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4607. }
  4608. //==========================================
  4609. // csu trigger ChangeAvailabilityConf
  4610. //==========================================
  4611. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4612. {
  4613. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4614. }
  4615. //==========================================
  4616. // csu trigger UnlockConnectorConf
  4617. //==========================================
  4618. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4619. {
  4620. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4621. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4622. }
  4623. //==========================================
  4624. // csu trigger ReserveNowConf
  4625. //==========================================
  4626. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4627. {
  4628. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4629. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4630. }
  4631. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4632. {
  4633. sendSignCertificateRequest();
  4634. }
  4635. }
  4636. }
  4637. //==========================================
  4638. // send request routine
  4639. //==========================================
  4640. int sendAuthorizeRequest(int gun_index)
  4641. {
  4642. mtrace();
  4643. int result = FAIL;
  4644. char message[100]={0};
  4645. char guid[37];
  4646. char tempdata[65]={0};
  4647. DEBUG_INFO("sendAuthorizeRequest...\n");
  4648. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4649. //Local Authorize
  4650. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4651. {
  4652. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4653. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4654. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4655. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4656. result = PASS;
  4657. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4658. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4659. authorizeRetryTimes = 0;
  4660. return result;
  4661. }
  4662. 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))||
  4663. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4664. {
  4665. // Query from cache
  4666. DEBUG_INFO("Authorize from cache.\n");
  4667. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4668. // Query from list
  4669. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4670. {
  4671. DEBUG_INFO("Authorize from list.\n");
  4672. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4673. }
  4674. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4675. {
  4676. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4677. {
  4678. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4679. }
  4680. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4681. {
  4682. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4683. }
  4684. if(!GetOcppConnStatus())
  4685. {
  4686. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4687. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4688. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4689. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4690. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4691. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4692. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4693. authorizeRetryTimes = 0;
  4694. return result;
  4695. }
  4696. }
  4697. else
  4698. {
  4699. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4700. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4701. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4702. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4703. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4704. else
  4705. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4706. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4707. result = PASS;
  4708. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4709. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4710. authorizeRetryTimes = 0;
  4711. return result;
  4712. }
  4713. }
  4714. //initialize struct Authorize
  4715. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4716. //get data from shared memory
  4717. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4718. random_uuid(guid);
  4719. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4720. LWS_Send(message);
  4721. sprintf(tempdata, "Authorize,%d", gun_index);
  4722. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4723. {
  4724. result = PASS;
  4725. DEBUG_INFO("Authorize mapItem pass\n");
  4726. }
  4727. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4728. return result;
  4729. }
  4730. int sendBootNotificationRequest(void)
  4731. {
  4732. mtrace();
  4733. int result = FAIL;
  4734. char message[500]={0}, payload[700]={0};
  4735. char guid[37]={0};
  4736. char tempdata[65]={0};
  4737. // Fill BootNotification fields
  4738. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4739. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4740. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4741. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4742. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4743. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4744. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4745. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4746. ShmOCPP16DataPH->ChargeBoxId
  4747. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4748. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4749. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4750. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4751. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4752. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4753. random_uuid(guid);
  4754. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4755. LWS_Send(message);
  4756. sprintf(tempdata, "BootNotification,0");
  4757. 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*/)
  4758. {
  4759. result = PASS;
  4760. }
  4761. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4762. strcpy(queuedata,message);
  4763. return result;
  4764. }
  4765. int sendDataTransferRequest(int gun_index)
  4766. {
  4767. mtrace();
  4768. char message[10240]={0};
  4769. char guid[37]={0};
  4770. char tempdata[65]={0};
  4771. int result = FAIL;
  4772. json_object *DataTransfer = json_object_new_object();
  4773. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId));
  4774. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId));
  4775. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data));
  4776. random_uuid(guid);
  4777. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  4778. guid,
  4779. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  4780. json_object_put(DataTransfer);
  4781. LWS_Send(message);
  4782. sprintf(tempdata, "DataTransfer,%d", gun_index);
  4783. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4784. {
  4785. result = PASS;
  4786. DEBUG_INFO("DataTransfer mapItem pass\n");
  4787. }
  4788. return result;
  4789. }
  4790. int sendUnplugByDataTransferRequest(int gun_index)
  4791. {
  4792. mtrace();
  4793. char message[10752]={0};
  4794. char guid[37]={0};
  4795. char tempdata[65]={0};
  4796. int result = FAIL;
  4797. random_uuid(guid);
  4798. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4799. (gun_index+1),
  4800. MESSAGE_TYPE_CALL,
  4801. guid,
  4802. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4803. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4804. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4805. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4806. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4807. {
  4808. result = PASS;
  4809. DEBUG_INFO("DataTransfer mapItem pass\n");
  4810. }
  4811. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  4812. return result;
  4813. }
  4814. int sendDiagnosticsStatusNotificationRequest(char *status)
  4815. {
  4816. mtrace();
  4817. int result = FAIL;
  4818. char message[110]={0};
  4819. char guid[37]={0};
  4820. char tempdata[65]={0};
  4821. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4822. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4823. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4824. random_uuid(guid);
  4825. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4826. LWS_SendNow(message);
  4827. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4828. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4829. {
  4830. result = PASS;
  4831. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4832. }
  4833. //#ifdef SystemLogMessage
  4834. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4835. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4836. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4837. //#endif
  4838. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4839. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4840. //record status
  4841. if(strcmp(status,"Idle")==0)
  4842. {
  4843. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4844. }
  4845. else if(strcmp(status,"Uploaded")==0)
  4846. {
  4847. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4848. }
  4849. else if(strcmp(status,"UploadFailed")==0)
  4850. {
  4851. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4852. }
  4853. else if(strcmp(status,"Uploading")==0)
  4854. {
  4855. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4856. }
  4857. return result;
  4858. }
  4859. int sendFirmwareStatusNotificationRequest(char *status)
  4860. {
  4861. mtrace();
  4862. int result = FAIL;
  4863. char message[110]={0};
  4864. char guid[37]={0};
  4865. char tempdata[65]={0};
  4866. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4867. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4868. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4869. random_uuid(guid);
  4870. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4871. LWS_SendNow(message);
  4872. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4873. 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*/)
  4874. {
  4875. result = PASS;
  4876. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4877. }
  4878. //#ifdef SystemLogMessage
  4879. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4880. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4881. //#endif
  4882. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4883. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4884. //record status
  4885. if(strcmp(status,"Downloaded")==0)
  4886. {
  4887. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4888. }
  4889. else if(strcmp(status,"DownloadFailed")==0)
  4890. {
  4891. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4892. }
  4893. else if(strcmp(status,"Downloading")==0)
  4894. {
  4895. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4896. }
  4897. else if(strcmp(status,"Idle")==0)
  4898. {
  4899. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4900. }
  4901. else if(strcmp(status,"InstallationFailed")==0)
  4902. {
  4903. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4904. }
  4905. else if(strcmp(status,"Installing")==0)
  4906. {
  4907. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4908. }
  4909. else if(strcmp(status,"Installed")==0)
  4910. {
  4911. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4912. }
  4913. return result;
  4914. }
  4915. int sendHeartbeatRequest(int gun_index)
  4916. {
  4917. mtrace();
  4918. int result = FAIL;
  4919. char message[80]={0};
  4920. char guid[37]={0};
  4921. char tempdata[65]={0};
  4922. random_uuid(guid);
  4923. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4924. , MESSAGE_TYPE_CALL
  4925. , guid );
  4926. LWS_Send(message);
  4927. sprintf(tempdata, "Heartbeat,%d", 0);
  4928. 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*/)
  4929. {
  4930. result = PASS;
  4931. }
  4932. return result;
  4933. }
  4934. int sendStartTransactionRequest(int gun_index)
  4935. {
  4936. mtrace();
  4937. int result = FAIL;
  4938. char message[250]={0};
  4939. char guid[37]={0};
  4940. struct timeval tmnow;
  4941. struct tm *tm;
  4942. char buf[28];//, usec_buf[6];
  4943. char tempdata[65]={0};
  4944. int tempIndex = 0;
  4945. DEBUG_INFO("sendStartTransactionRequest...\n");
  4946. gettimeofday(&tmnow, NULL);
  4947. time_t t;
  4948. t = time(NULL);
  4949. /*UTC time and date*/
  4950. tm = gmtime(&t);
  4951. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4952. #if 0 // remove temporally
  4953. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4954. strcat(buf,".");
  4955. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4956. strcat(buf,usec_buf);
  4957. #endif
  4958. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4959. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4960. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4961. // clear StartTransaction Response
  4962. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4963. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4964. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4965. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4966. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4967. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4968. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4969. {
  4970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4971. {
  4972. tempIndex = ((gun_index==2) ? 1: 0);
  4973. }
  4974. else
  4975. {
  4976. tempIndex = gun_index;
  4977. }
  4978. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4979. {
  4980. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4981. {
  4982. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4983. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4984. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4985. }
  4986. }
  4987. }
  4988. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4989. {
  4990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4991. {
  4992. tempIndex = ((gun_index==2) ? 1: 0);
  4993. }
  4994. else
  4995. {
  4996. tempIndex = gun_index;
  4997. }
  4998. for (int index = 0; index < CCS_QUANTITY; index++)
  4999. {
  5000. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5001. {
  5002. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5003. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5004. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5005. }
  5006. }
  5007. }
  5008. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5009. {
  5010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5011. {
  5012. tempIndex = ((gun_index==2) ? 1: 0);
  5013. }
  5014. else
  5015. {
  5016. tempIndex = gun_index;
  5017. }
  5018. for (int index = 0; index < GB_QUANTITY; index++)
  5019. {
  5020. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5021. {
  5022. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5023. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5024. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5025. }
  5026. }
  5027. }
  5028. else if(gunType[gun_index] == GUN_TYPE_DO)
  5029. {
  5030. tempIndex = gun_index;
  5031. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5032. {
  5033. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5034. {
  5035. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5036. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5037. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5038. }
  5039. }
  5040. }
  5041. else
  5042. {
  5043. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5044. {
  5045. tempIndex = 2;
  5046. }
  5047. else
  5048. {
  5049. tempIndex = gun_index;
  5050. }
  5051. for (int index = 0; index < AC_QUANTITY; index++)
  5052. {
  5053. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5054. {
  5055. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5056. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5057. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5058. }
  5059. }
  5060. }
  5061. random_uuid(guid);
  5062. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5063. {
  5064. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5065. , gun_index +1
  5066. , MESSAGE_TYPE_CALL
  5067. , guid
  5068. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5069. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5070. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5071. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5072. }
  5073. else
  5074. {
  5075. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5076. , gun_index +1
  5077. , MESSAGE_TYPE_CALL
  5078. , guid
  5079. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5080. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5081. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5082. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  5083. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5084. }
  5085. #if 1
  5086. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5087. 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*/)
  5088. {
  5089. result = PASS;
  5090. }
  5091. #endif
  5092. strcpy(queuedata, message);
  5093. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5094. OCPP_insert_transaction_msg(YES, queuedata);
  5095. return result;
  5096. }
  5097. int sendStatusNotificationRequest(int gun_index)
  5098. {
  5099. mtrace();
  5100. int result = FAIL;
  5101. char message[600]={0};
  5102. char guid[37];
  5103. int currentStatus = 0;
  5104. struct timeval tmnow;
  5105. struct tm *tm;
  5106. char buf[28];//, usec_buf[6];
  5107. char tempdata[65]={0};
  5108. int tempIndex = 0;
  5109. uint8_t isStateChanged = TRUE;
  5110. uint8_t isContentIllegal = TRUE;
  5111. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5112. gettimeofday(&tmnow, NULL);
  5113. time_t t;
  5114. t = time(NULL);
  5115. /*UTC time and date*/
  5116. tm = gmtime(&t);
  5117. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5118. #if 0 // remove temporally
  5119. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5120. strcat(buf,".");
  5121. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5122. strcat(buf,usec_buf);
  5123. #endif
  5124. //printf("%s",buf);
  5125. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5126. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5127. // it's option
  5128. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5129. /*
  5130. enum _SYSTEM_STATUS
  5131. {
  5132. S_BOOTING = 0,
  5133. S_IDLE, = 1
  5134. S_AUTHORIZING, =2
  5135. S_REASSIGN_CHECK, =3
  5136. S_REASSIGN, =4
  5137. S_PRECHARGE, =5
  5138. S_PREPARING_FOR_EV, =6
  5139. S_PREPARING_FOR_EVSE, =7
  5140. S_CHARGING, =8
  5141. S_TERMINATING, =9
  5142. S_COMPLETE, =10
  5143. S_ALARM, =11
  5144. S_FAULT =12
  5145. }
  5146. */
  5147. //check Transaction active
  5148. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5149. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5150. {
  5151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5152. {
  5153. tempIndex = ((gun_index==2) ? 1: 0);
  5154. }
  5155. else
  5156. {
  5157. tempIndex = gun_index;
  5158. }
  5159. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5160. {
  5161. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5162. {
  5163. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5164. {
  5165. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5166. {
  5167. currentStatus = Preparing; //OCPP Status: Preparing
  5168. }
  5169. else
  5170. {
  5171. currentStatus = Available; //OCPP Status: Available
  5172. }
  5173. }
  5174. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5175. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5176. ) //S_PRECHARGE
  5177. {
  5178. currentStatus = Preparing; //OCPP Status: Preparing
  5179. }
  5180. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5181. {
  5182. currentStatus = Charging; //OCPP Status: Charging
  5183. }
  5184. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5185. {
  5186. currentStatus = Finishing; //OCPP Status: Finishing
  5187. }
  5188. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5189. {
  5190. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5191. }
  5192. 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
  5193. {
  5194. currentStatus = Unavailable; //OCPP Status: Unavailable
  5195. }
  5196. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5197. {
  5198. currentStatus = Faulted; //OCPP Status: Faulted
  5199. }
  5200. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5201. {
  5202. currentStatus = Reserved; //OCPP Status: Reserved
  5203. }
  5204. } //end of the same index
  5205. }//end of for CHAdeMO_QUANTITY
  5206. }
  5207. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5208. {
  5209. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5210. {
  5211. tempIndex = ((gun_index==2) ? 1: 0);
  5212. }
  5213. else
  5214. {
  5215. tempIndex = gun_index;
  5216. }
  5217. for (int index = 0; index < CCS_QUANTITY; index++)
  5218. {
  5219. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5220. {
  5221. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5222. {
  5223. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5224. {
  5225. currentStatus = Preparing; //OCPP Status: Preparing
  5226. }
  5227. else
  5228. {
  5229. currentStatus = Available; //OCPP Status: Available
  5230. }
  5231. }
  5232. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5233. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5234. ) //S_PRECHARGE
  5235. {
  5236. currentStatus = Preparing; //OCPP Status: Preparing
  5237. }
  5238. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5239. {
  5240. currentStatus = Charging; //OCPP Status: Charging
  5241. }
  5242. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5243. {
  5244. currentStatus = Finishing; //OCPP Status: Finishing
  5245. }
  5246. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5247. {
  5248. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5249. }
  5250. 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
  5251. {
  5252. currentStatus = Unavailable; //OCPP Status : Unavailable
  5253. }
  5254. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5255. {
  5256. currentStatus = Faulted; //OCPP Status: Faulted
  5257. }
  5258. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5259. {
  5260. currentStatus = Reserved; //OCPP Status: Reserved
  5261. }
  5262. } //end of the same index
  5263. } // end of for CCS_QUANTITY
  5264. }
  5265. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5266. {
  5267. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5268. {
  5269. tempIndex = ((gun_index==2) ? 1: 0);
  5270. }
  5271. else
  5272. {
  5273. tempIndex = gun_index;
  5274. }
  5275. for (int index = 0; index < GB_QUANTITY; index++)
  5276. {
  5277. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5278. {
  5279. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5280. {
  5281. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5282. {
  5283. currentStatus = Preparing; //OCPP Status: Preparing
  5284. }
  5285. else
  5286. {
  5287. currentStatus = Available; //OCPP Status: Available
  5288. }
  5289. }
  5290. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5291. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5292. ) //S_PRECHARGE
  5293. {
  5294. currentStatus = Preparing; //OCPP Status: Preparing
  5295. }
  5296. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5297. {
  5298. currentStatus = Charging; //OCPP Status: Charging
  5299. }
  5300. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5301. {
  5302. currentStatus = Finishing; //OCPP Status: Finishing
  5303. }
  5304. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5305. {
  5306. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5307. }
  5308. 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
  5309. {
  5310. currentStatus = Unavailable; //OCPP Status: Unavailable
  5311. }
  5312. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5313. {
  5314. currentStatus = Faulted; //OCPP Status: Faulted
  5315. }
  5316. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5317. {
  5318. currentStatus = Reserved; //OCPP Status: Reserved
  5319. }
  5320. } //end of the same index
  5321. } // end of for GB_QUANTITY
  5322. }
  5323. else if(gunType[gun_index] == GUN_TYPE_DO)
  5324. {
  5325. tempIndex = gun_index;
  5326. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5327. {
  5328. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5329. {
  5330. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5331. {
  5332. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5333. {
  5334. currentStatus = Preparing; //OCPP Status: Preparing
  5335. }
  5336. else
  5337. {
  5338. currentStatus = Available; //OCPP Status: Available
  5339. }
  5340. }
  5341. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5342. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5343. ) //S_PRECHARGE
  5344. {
  5345. currentStatus = Preparing; //OCPP Status: Preparing
  5346. }
  5347. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5348. {
  5349. currentStatus = Charging; //OCPP Status: Charging
  5350. }
  5351. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5352. {
  5353. currentStatus = Finishing; //OCPP Status: Finishing
  5354. }
  5355. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5356. {
  5357. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5358. }
  5359. 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
  5360. {
  5361. currentStatus = Unavailable; //OCPP Status: Unavailable
  5362. }
  5363. 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
  5364. {
  5365. currentStatus = Faulted; //OCPP Status: Faulted
  5366. }
  5367. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5368. {
  5369. currentStatus = Reserved; //OCPP Status: Reserved
  5370. }
  5371. } //end of the same index
  5372. }
  5373. }
  5374. else
  5375. {
  5376. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5377. {
  5378. tempIndex = 2;
  5379. }
  5380. else
  5381. {
  5382. tempIndex = gun_index;
  5383. }
  5384. for (int index = 0; index < AC_QUANTITY; index++)
  5385. {
  5386. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5387. {
  5388. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5389. {
  5390. 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))
  5391. {
  5392. currentStatus = Preparing; //OCPP Status: Preparing
  5393. }
  5394. else
  5395. {
  5396. currentStatus = Available; //OCPP Status: Available
  5397. }
  5398. }
  5399. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5400. {
  5401. currentStatus = Preparing; //OCPP Status: Preparing
  5402. }
  5403. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5404. {
  5405. currentStatus = Charging; //OCPP Status: Charging
  5406. }
  5407. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5408. {
  5409. currentStatus = Finishing; //OCPP Status: Finishing
  5410. }
  5411. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5412. {
  5413. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5414. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5415. else
  5416. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5417. }
  5418. 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
  5419. {
  5420. currentStatus = Unavailable; //OCPP Status: Unavailable
  5421. }
  5422. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5423. {
  5424. currentStatus = Faulted; //OCPP Status: Faulted
  5425. }
  5426. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5427. {
  5428. currentStatus = Reserved; //OCPP Status: Reserved
  5429. }
  5430. }//end of the same index
  5431. }//end of for AC_QUANTITY
  5432. }
  5433. //it's option
  5434. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5435. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5436. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5437. {
  5438. isStateChanged = FALSE;
  5439. }
  5440. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5441. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5442. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5443. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5444. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5445. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5446. isContentIllegal = TRUE;
  5447. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5448. {
  5449. if(strcmp((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5450. {
  5451. isContentIllegal = FALSE;
  5452. break;
  5453. }
  5454. }
  5455. if(isContentIllegal)
  5456. {
  5457. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5458. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5459. }
  5460. random_uuid(guid);
  5461. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5462. , MESSAGE_TYPE_CALL
  5463. , guid
  5464. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5465. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5466. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5467. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5468. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5469. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5470. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5471. if((server_sign == TRUE) && isStateChanged)
  5472. {
  5473. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5474. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5475. LWS_Send(message);
  5476. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5477. 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*/)
  5478. {
  5479. //DEBUG_ERROR("statusNotification mapitem pass");
  5480. result = PASS;
  5481. }
  5482. }
  5483. else
  5484. {
  5485. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5486. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5487. result = PASS;
  5488. }
  5489. return result;
  5490. }
  5491. int sendStopTransactionRequest(int gun_index)
  5492. {
  5493. mtrace();
  5494. int result = FAIL;
  5495. //char message[1500]={0};
  5496. char guid[37]={0};
  5497. char tempdata[65]={0};
  5498. int tempIndex = 0;
  5499. char TempStopTransaction[256];
  5500. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5501. //int idx_sample=0;
  5502. DEBUG_INFO("sendStopTransactionRequest \n");
  5503. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5504. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5505. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5506. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5507. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5508. {
  5509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5510. {
  5511. tempIndex = ((gun_index==2) ? 1: 0);
  5512. }
  5513. else
  5514. {
  5515. tempIndex = gun_index;
  5516. }
  5517. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5518. {
  5519. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5520. {
  5521. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5522. }
  5523. }// END OF CHAdeMO_QUANTITY
  5524. }
  5525. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5526. {
  5527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5528. {
  5529. tempIndex = ((gun_index==2) ? 1: 0);
  5530. }
  5531. else
  5532. {
  5533. tempIndex = gun_index;
  5534. }
  5535. for (int index = 0; index < CCS_QUANTITY; index++)
  5536. {
  5537. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5538. {
  5539. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5540. }
  5541. }// END OF CCS_QUANTITY
  5542. }
  5543. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5544. {
  5545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5546. {
  5547. tempIndex = ((gun_index==2) ? 1: 0);
  5548. }
  5549. else
  5550. {
  5551. tempIndex = gun_index;
  5552. }
  5553. for (int index = 0; index < GB_QUANTITY; index++)
  5554. {
  5555. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5556. {
  5557. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5558. }
  5559. }// END OF GB_QUANTITY
  5560. }
  5561. else if(gunType[gun_index] == GUN_TYPE_DO)
  5562. {
  5563. tempIndex = gun_index;
  5564. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5565. {
  5566. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5567. {
  5568. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5569. }
  5570. }// END OF GB_QUANTITY
  5571. }
  5572. else
  5573. {
  5574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5575. {
  5576. tempIndex = 2;
  5577. }
  5578. else
  5579. {
  5580. tempIndex = gun_index;
  5581. }
  5582. for (int index = 0; index < AC_QUANTITY; index++)
  5583. {
  5584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5585. {
  5586. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5587. }
  5588. }// END OF AC_QUANTITY
  5589. }
  5590. //====================================== Stop Transaction Time =====================================================
  5591. struct timeval tmnow;
  5592. struct tm *tm;
  5593. char buf[28];//, usec_buf[6];
  5594. gettimeofday(&tmnow, NULL);
  5595. time_t t;
  5596. t = time(NULL);
  5597. /*UTC time and date*/
  5598. tm = gmtime(&t);
  5599. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5600. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5601. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5602. random_uuid(guid);
  5603. /***********************************transactionData******************************************************/
  5604. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5605. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5606. //=================================
  5607. // Transaction_Begin
  5608. //=================================
  5609. //=================================
  5610. // Transaction_End
  5611. //=================================
  5612. // ================================= Current.Import L1 ===============================================
  5613. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5614. {
  5615. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5616. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5617. {
  5618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5619. {
  5620. tempIndex = ((gun_index==2) ? 1: 0);
  5621. }
  5622. else
  5623. {
  5624. tempIndex = gun_index;
  5625. }
  5626. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5627. {
  5628. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5629. {
  5630. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5631. }
  5632. }// End of for CHAdeMO_QUANTITY
  5633. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5634. }
  5635. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5636. {
  5637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5638. {
  5639. tempIndex = ((gun_index==2) ? 1: 0);
  5640. }
  5641. else
  5642. {
  5643. tempIndex = gun_index;
  5644. }
  5645. for (int index = 0; index < CCS_QUANTITY; index++)
  5646. {
  5647. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5648. {
  5649. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5650. }
  5651. }// End of for CCS_QUANTITY
  5652. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5653. }
  5654. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5655. {
  5656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5657. {
  5658. tempIndex = ((gun_index==2) ? 1: 0);
  5659. }
  5660. else
  5661. {
  5662. tempIndex = gun_index;
  5663. }
  5664. for (int index = 0; index < GB_QUANTITY; index++)
  5665. {
  5666. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5667. {
  5668. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5669. }
  5670. }// End of for GB_QUANTITY
  5671. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5672. }
  5673. else if(gunType[gun_index] == GUN_TYPE_DO)
  5674. {
  5675. tempIndex = gun_index;
  5676. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5677. {
  5678. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5679. {
  5680. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5681. }
  5682. }
  5683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5684. }
  5685. else
  5686. {
  5687. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5688. {
  5689. tempIndex = 2;
  5690. }
  5691. else
  5692. {
  5693. tempIndex = gun_index;
  5694. }
  5695. for (int index = 0; index < AC_QUANTITY; index++)
  5696. {
  5697. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5698. {
  5699. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5700. }
  5701. }// End of for AC_QUANTITY
  5702. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5703. }
  5704. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5705. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5706. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5707. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5708. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5709. }
  5710. // ================================= Energy.Active.Import.Interval ==============================================
  5711. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5712. {
  5713. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5714. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5715. {
  5716. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5717. {
  5718. tempIndex = ((gun_index==2) ? 1: 0);
  5719. }
  5720. else
  5721. {
  5722. tempIndex = gun_index;
  5723. }
  5724. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5725. {
  5726. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5727. {
  5728. 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
  5729. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5730. }
  5731. }// END OF CHAdeMO_QUANTITY
  5732. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5733. }
  5734. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5735. {
  5736. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5737. {
  5738. tempIndex = ((gun_index==2) ? 1: 0);
  5739. }
  5740. else
  5741. {
  5742. tempIndex = gun_index;
  5743. }
  5744. for (int index = 0; index < CCS_QUANTITY; index++)
  5745. {
  5746. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5747. {
  5748. 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
  5749. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5750. }
  5751. }// END OF CCS_QUANTITY
  5752. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5753. }
  5754. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5755. {
  5756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5757. {
  5758. tempIndex = ((gun_index==2) ? 1: 0);
  5759. }
  5760. else
  5761. {
  5762. tempIndex = gun_index;
  5763. }
  5764. for (int index = 0; index < GB_QUANTITY; index++)
  5765. {
  5766. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5767. {
  5768. 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
  5769. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5770. }
  5771. }// END OF GB_QUANTITY
  5772. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5773. }
  5774. else if(gunType[gun_index] == GUN_TYPE_DO)
  5775. {
  5776. tempIndex = gun_index;
  5777. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5778. {
  5779. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5780. {
  5781. 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
  5782. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5783. }
  5784. }
  5785. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5786. }
  5787. else
  5788. {
  5789. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5790. {
  5791. tempIndex = 2;
  5792. }
  5793. else
  5794. {
  5795. tempIndex = gun_index;
  5796. }
  5797. for (int index = 0; index < AC_QUANTITY; index++)
  5798. {
  5799. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5800. {
  5801. 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
  5802. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5803. }
  5804. }// END OF AC_QUANTITY
  5805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5806. }
  5807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5809. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5810. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5811. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5812. }
  5813. //=================================== Power.Active.Import ==================================================
  5814. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5815. {
  5816. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5817. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5818. {
  5819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5820. {
  5821. tempIndex = ((gun_index==2) ? 1: 0);
  5822. }
  5823. else
  5824. {
  5825. tempIndex = gun_index;
  5826. }
  5827. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5828. {
  5829. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5830. {
  5831. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5832. }
  5833. } // End for CHAdeMO_QUANTITY
  5834. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5835. }
  5836. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5837. {
  5838. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5839. {
  5840. tempIndex = ((gun_index==2) ? 1: 0);
  5841. }
  5842. else
  5843. {
  5844. tempIndex = gun_index;
  5845. }
  5846. for (int index = 0; index < CCS_QUANTITY; index++)
  5847. {
  5848. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5849. {
  5850. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5851. }
  5852. } // END for CCS_QUANTITY
  5853. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5854. }
  5855. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5856. {
  5857. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5858. {
  5859. tempIndex = ((gun_index==2) ? 1: 0);
  5860. }
  5861. else
  5862. {
  5863. tempIndex = gun_index;
  5864. }
  5865. for (int index = 0; index < GB_QUANTITY; index++)
  5866. {
  5867. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5868. {
  5869. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5870. }
  5871. }// END for GB_QUANTITY
  5872. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5873. }
  5874. else if(gunType[gun_index] == GUN_TYPE_DO)
  5875. {
  5876. tempIndex = gun_index;
  5877. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5878. {
  5879. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5880. {
  5881. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5882. }
  5883. }
  5884. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5885. }
  5886. else
  5887. {
  5888. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5889. {
  5890. tempIndex = 2;
  5891. }
  5892. else
  5893. {
  5894. tempIndex = gun_index;
  5895. }
  5896. for (int index = 0; index < AC_QUANTITY; index++)
  5897. {
  5898. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5899. {
  5900. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5901. }
  5902. } // END for AC_QUANTITY
  5903. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5904. }
  5905. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5906. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5907. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5908. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5909. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5910. }
  5911. //============================ Voltage L1 ====================================
  5912. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5913. {
  5914. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5915. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5916. {
  5917. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5918. {
  5919. tempIndex = ((gun_index==2) ? 1: 0);
  5920. }
  5921. else
  5922. {
  5923. tempIndex = gun_index;
  5924. }
  5925. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5926. {
  5927. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5928. {
  5929. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5930. }
  5931. } // END OF FOR CHAdeMO_QUANTITY
  5932. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5933. }
  5934. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5935. {
  5936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5937. {
  5938. tempIndex = ((gun_index==2) ? 1: 0);
  5939. }
  5940. else
  5941. {
  5942. tempIndex = gun_index;
  5943. }
  5944. for (int index = 0; index < CCS_QUANTITY; index++)
  5945. {
  5946. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5947. {
  5948. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5949. }
  5950. } // END OF FOR CCS_QUANTITY
  5951. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5952. }
  5953. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5954. {
  5955. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5956. {
  5957. tempIndex = ((gun_index==2) ? 1: 0);
  5958. }
  5959. else
  5960. {
  5961. tempIndex = gun_index;
  5962. }
  5963. for (int index = 0; index < GB_QUANTITY; index++)
  5964. {
  5965. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5966. {
  5967. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5968. }
  5969. } // END OF FOR GB_QUANTITY
  5970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5971. }
  5972. else if(gunType[gun_index] == GUN_TYPE_DO)
  5973. {
  5974. tempIndex = gun_index;
  5975. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5976. {
  5977. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5978. {
  5979. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5980. }
  5981. }
  5982. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5983. }
  5984. else
  5985. {
  5986. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5987. {
  5988. tempIndex = 2;
  5989. }
  5990. else
  5991. {
  5992. tempIndex = gun_index;
  5993. }
  5994. for (int index = 0; index < AC_QUANTITY; index++)
  5995. {
  5996. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5997. {
  5998. 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
  5999. }
  6000. } // END OF FOR AC_QUANTITY
  6001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6002. }
  6003. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6004. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6005. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6006. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6007. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6008. }
  6009. //====================== End SoC ================================
  6010. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6011. {
  6012. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6013. 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))
  6014. {
  6015. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6016. {
  6017. tempIndex = ((gun_index==2) ? 1: 0);
  6018. }
  6019. else
  6020. {
  6021. tempIndex = gun_index;
  6022. }
  6023. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6024. {
  6025. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6026. {
  6027. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6028. {
  6029. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6030. }
  6031. }
  6032. }
  6033. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6034. {
  6035. for (int index = 0; index < CCS_QUANTITY; index++)
  6036. {
  6037. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6038. {
  6039. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6040. }
  6041. }
  6042. }
  6043. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6044. {
  6045. for (int index = 0; index < GB_QUANTITY; index++)
  6046. {
  6047. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6048. {
  6049. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6050. }
  6051. }
  6052. }
  6053. else if(gunType[gun_index] == GUN_TYPE_DO)
  6054. {
  6055. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6056. {
  6057. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6058. {
  6059. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6060. }
  6061. }
  6062. }
  6063. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6064. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6065. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6066. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6067. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6068. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6069. } // END FOR DC CASE
  6070. }
  6071. // ================================= Current.Import L2 ===============================================
  6072. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6073. {
  6074. // AC 3 phse L2 current
  6075. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6076. {
  6077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6078. {
  6079. tempIndex = 2;
  6080. }
  6081. else
  6082. {
  6083. tempIndex = gun_index;
  6084. }
  6085. for (int index = 0; index < AC_QUANTITY; index++)
  6086. {
  6087. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6088. {
  6089. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6090. }
  6091. }// End of for AC_QUANTITY
  6092. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6093. }
  6094. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6095. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6096. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6097. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6098. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6099. }
  6100. // ================================= Current.Import L3 ===============================================
  6101. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6102. {
  6103. // AC 3 phse L3 current
  6104. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6105. {
  6106. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6107. {
  6108. tempIndex = 2;
  6109. }
  6110. else
  6111. {
  6112. tempIndex = gun_index;
  6113. }
  6114. for (int index = 0; index < AC_QUANTITY; index++)
  6115. {
  6116. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6117. {
  6118. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6119. }
  6120. }// End of for AC_QUANTITY
  6121. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6122. }
  6123. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6124. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6125. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6126. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6127. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6128. }
  6129. //============================ Voltage L2 ====================================
  6130. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6131. {
  6132. // AC 3 phse L2 voltage
  6133. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6134. {
  6135. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6136. {
  6137. tempIndex = 2;
  6138. }
  6139. else
  6140. {
  6141. tempIndex = gun_index;
  6142. }
  6143. for (int index = 0; index < AC_QUANTITY; index++)
  6144. {
  6145. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6146. {
  6147. 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
  6148. }
  6149. } // END OF FOR AC_QUANTITY
  6150. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6151. }
  6152. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6153. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6154. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6155. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6156. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6157. }
  6158. //============================ Voltage L3 ====================================
  6159. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6160. {
  6161. // AC 3 phse L3 voltage
  6162. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6163. {
  6164. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6165. {
  6166. tempIndex = 2;
  6167. }
  6168. else
  6169. {
  6170. tempIndex = gun_index;
  6171. }
  6172. for (int index = 0; index < AC_QUANTITY; index++)
  6173. {
  6174. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6175. {
  6176. 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
  6177. }
  6178. } // END OF FOR AC_QUANTITY
  6179. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6180. }
  6181. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6182. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6183. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6184. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6185. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6186. }
  6187. //====================== Start SoC ================================
  6188. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6189. {
  6190. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6191. 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))
  6192. {
  6193. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6194. {
  6195. tempIndex = ((gun_index==2) ? 1: 0);
  6196. }
  6197. else
  6198. {
  6199. tempIndex = gun_index;
  6200. }
  6201. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6202. {
  6203. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6204. {
  6205. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6206. {
  6207. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6208. }
  6209. }
  6210. }
  6211. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6212. {
  6213. for (int index = 0; index < CCS_QUANTITY; index++)
  6214. {
  6215. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6216. {
  6217. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6218. }
  6219. }
  6220. }
  6221. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6222. {
  6223. for (int index = 0; index < GB_QUANTITY; index++)
  6224. {
  6225. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6226. {
  6227. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6228. }
  6229. }
  6230. }
  6231. else if(gunType[gun_index] == GUN_TYPE_DO)
  6232. {
  6233. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6234. {
  6235. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6236. {
  6237. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6238. }
  6239. }
  6240. }
  6241. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6242. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6243. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6244. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6245. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6246. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6247. } // END FOR DC CASE
  6248. }
  6249. //================================================ Message create ====================================================
  6250. json_object *StopTransaction = json_object_new_object();
  6251. json_object *transactionDatas = json_object_new_array();
  6252. json_object *sampledValues = json_object_new_array();
  6253. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6254. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6255. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6256. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6257. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6258. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6259. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6260. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6261. {
  6262. json_object *transactionData = json_object_new_object();
  6263. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6264. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6265. {
  6266. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6267. {
  6268. json_object *sampledValue = json_object_new_object();
  6269. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6270. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6271. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6272. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6273. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6274. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6275. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6276. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6277. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6278. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6279. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6280. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6281. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6282. json_object_array_add(sampledValues, sampledValue);
  6283. }
  6284. }
  6285. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6286. json_object_array_add(transactionDatas, transactionData);
  6287. }
  6288. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6289. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6290. ,MESSAGE_TYPE_CALL
  6291. ,guid
  6292. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6293. json_object_put(StopTransaction);
  6294. #if 1 // for TempStopTransaction
  6295. //Delete TempStopTransaction
  6296. if((access(TempStopTransaction,F_OK))!=-1)
  6297. {
  6298. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6299. }
  6300. #endif
  6301. #if 1
  6302. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6303. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6304. {
  6305. result = PASS;
  6306. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6307. }
  6308. #endif
  6309. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6310. OCPP_insert_transaction_msg(NO, queuedata);
  6311. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6312. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6313. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6314. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6315. {
  6316. //SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6317. }
  6318. //for test
  6319. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6320. return result;
  6321. }
  6322. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6323. {
  6324. mtrace();
  6325. int result = FAIL;
  6326. char guid[37]={0};
  6327. char tempdata[65]={0};
  6328. int tempIndex = 0;
  6329. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6330. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6331. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6332. //set value
  6333. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6334. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6335. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6336. -1);
  6337. random_uuid(guid);
  6338. //UTC Date time
  6339. struct timeval tmnow;
  6340. struct tm *tm;
  6341. char buf[28];//, usec_buf[6];
  6342. gettimeofday(&tmnow, NULL);
  6343. time_t t;
  6344. t = time(NULL);
  6345. /*UTC time and date*/
  6346. tm = gmtime(&t);
  6347. if(dataType == ReadingContext_Sample_Clock)
  6348. {
  6349. struct tm *tmTarget;
  6350. struct timeb tbTarget;
  6351. tbTarget.time = mktime(tm);
  6352. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6353. tmTarget = gmtime(&tbTarget.time);
  6354. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6355. }
  6356. else
  6357. {
  6358. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6359. }
  6360. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6361. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6362. //********************************(1)Current.Import L1************************************************/
  6363. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6364. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6365. (dataType == ReadingContext_Trigger))
  6366. {
  6367. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6368. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6369. {
  6370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6371. {
  6372. tempIndex = ((gun_index==2) ? 1: 0);
  6373. }
  6374. else
  6375. {
  6376. tempIndex = gun_index;
  6377. }
  6378. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6379. {
  6380. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6381. {
  6382. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6383. }
  6384. }
  6385. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6386. }
  6387. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6388. {
  6389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6390. {
  6391. tempIndex = ((gun_index==2) ? 1: 0);
  6392. }
  6393. else
  6394. {
  6395. tempIndex = gun_index;
  6396. }
  6397. for (int index = 0; index < CCS_QUANTITY; index++)
  6398. {
  6399. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6400. {
  6401. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6402. }
  6403. }
  6404. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6405. }
  6406. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6407. {
  6408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6409. {
  6410. tempIndex = ((gun_index==2) ? 1: 0);
  6411. }
  6412. else
  6413. {
  6414. tempIndex = gun_index;
  6415. }
  6416. for (int index = 0; index < GB_QUANTITY; index++)
  6417. {
  6418. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6419. {
  6420. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6421. }
  6422. }
  6423. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6424. }
  6425. else if(gunType[gun_index] == GUN_TYPE_DO)
  6426. {
  6427. tempIndex = gun_index;
  6428. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6429. {
  6430. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6431. {
  6432. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6433. }
  6434. }
  6435. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6436. }
  6437. else
  6438. {
  6439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6440. {
  6441. tempIndex = 2;
  6442. }
  6443. else
  6444. {
  6445. tempIndex = gun_index;
  6446. }
  6447. for (int index = 0; index < AC_QUANTITY; index++)
  6448. {
  6449. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6450. {
  6451. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6452. }
  6453. }
  6454. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6455. }
  6456. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6457. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6458. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6459. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6460. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6461. }
  6462. //********************************(2)Energy.Active.Import.Register ************************************************/
  6463. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6464. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6465. (dataType == ReadingContext_Trigger))
  6466. {
  6467. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6468. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6469. {
  6470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6471. {
  6472. tempIndex = ((gun_index==2) ? 1: 0);
  6473. }
  6474. else
  6475. {
  6476. tempIndex = gun_index;
  6477. }
  6478. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6479. {
  6480. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6481. {
  6482. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6483. }
  6484. }
  6485. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6486. }
  6487. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6488. {
  6489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6490. {
  6491. tempIndex = ((gun_index==2) ? 1: 0);
  6492. }
  6493. else
  6494. {
  6495. tempIndex = gun_index;
  6496. }
  6497. for (int index = 0; index < CCS_QUANTITY; index++)
  6498. {
  6499. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6500. {
  6501. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6502. }
  6503. }
  6504. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6505. }
  6506. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6507. {
  6508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6509. {
  6510. tempIndex = ((gun_index==2) ? 1: 0);
  6511. }
  6512. else
  6513. {
  6514. tempIndex = gun_index;
  6515. }
  6516. for (int index = 0; index < GB_QUANTITY; index++)
  6517. {
  6518. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6519. {
  6520. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6521. }
  6522. }
  6523. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6524. }
  6525. else if(gunType[gun_index] == GUN_TYPE_DO)
  6526. {
  6527. tempIndex = gun_index;
  6528. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6529. {
  6530. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6531. {
  6532. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6533. }
  6534. }
  6535. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6536. }
  6537. else
  6538. {
  6539. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6540. {
  6541. tempIndex = 2;
  6542. }
  6543. else
  6544. {
  6545. tempIndex = gun_index;
  6546. }
  6547. for (int index = 0; index < AC_QUANTITY; index++)
  6548. {
  6549. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6550. {
  6551. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6552. }
  6553. }
  6554. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6555. }
  6556. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6557. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6558. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6559. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6560. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6561. }
  6562. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6563. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6564. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6565. (dataType == ReadingContext_Trigger))
  6566. {
  6567. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6568. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6569. {
  6570. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6571. {
  6572. tempIndex = ((gun_index==2) ? 1: 0);
  6573. }
  6574. else
  6575. {
  6576. tempIndex = gun_index;
  6577. }
  6578. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6579. {
  6580. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6581. {
  6582. if(dataType == ReadingContext_Sample_Clock)
  6583. {
  6584. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6585. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6586. }
  6587. else if(dataType == ReadingContext_Sample_Periodic)
  6588. {
  6589. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6590. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6591. }
  6592. else
  6593. {
  6594. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6595. }
  6596. }
  6597. } // END OF FOR CHAdeMO_QUANTITY
  6598. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6599. }
  6600. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6601. {
  6602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6603. {
  6604. tempIndex = ((gun_index==2) ? 1: 0);
  6605. }
  6606. else
  6607. {
  6608. tempIndex = gun_index;
  6609. }
  6610. for (int index = 0; index < CCS_QUANTITY; index++)
  6611. {
  6612. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6613. {
  6614. if(dataType == ReadingContext_Sample_Clock)
  6615. {
  6616. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6617. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6618. }
  6619. else if(dataType == ReadingContext_Sample_Periodic)
  6620. {
  6621. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6622. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6623. }
  6624. else
  6625. {
  6626. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6627. }
  6628. }
  6629. } // END OF CCS_QUANTITY
  6630. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6631. }
  6632. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6633. {
  6634. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6635. {
  6636. tempIndex = ((gun_index==2) ? 1: 0);
  6637. }
  6638. else
  6639. {
  6640. tempIndex = gun_index;
  6641. }
  6642. for (int index = 0; index < GB_QUANTITY; index++)
  6643. {
  6644. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6645. {
  6646. if(dataType == ReadingContext_Sample_Clock)
  6647. {
  6648. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6649. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6650. }
  6651. else if(dataType == ReadingContext_Sample_Periodic)
  6652. {
  6653. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6654. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6655. }
  6656. else
  6657. {
  6658. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6659. }
  6660. }
  6661. } // END OF GB_QUANTITY
  6662. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6663. }
  6664. else if(gunType[gun_index] == GUN_TYPE_DO)
  6665. {
  6666. tempIndex = gun_index;
  6667. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6668. {
  6669. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6670. {
  6671. if(dataType == ReadingContext_Sample_Clock)
  6672. {
  6673. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  6674. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6675. }
  6676. else if(dataType == ReadingContext_Sample_Periodic)
  6677. {
  6678. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6679. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6680. }
  6681. else
  6682. {
  6683. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6684. }
  6685. }
  6686. }
  6687. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6688. }
  6689. else
  6690. {
  6691. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6692. {
  6693. tempIndex = 2;
  6694. }
  6695. else
  6696. {
  6697. tempIndex = gun_index;
  6698. }
  6699. for (int index = 0; index < AC_QUANTITY; index++)
  6700. {
  6701. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6702. {
  6703. if(dataType == ReadingContext_Sample_Clock)
  6704. {
  6705. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6706. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6707. }
  6708. else if(dataType == ReadingContext_Sample_Periodic)
  6709. {
  6710. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6711. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6712. }
  6713. else
  6714. {
  6715. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6716. }
  6717. }
  6718. }
  6719. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6720. }
  6721. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6722. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6723. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6724. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6725. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6726. }
  6727. //********************************(4)Power.Active.Import************************************************/
  6728. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6729. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6730. (dataType == ReadingContext_Trigger))
  6731. {
  6732. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6733. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6734. {
  6735. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6736. {
  6737. tempIndex = ((gun_index==2) ? 1: 0);
  6738. }
  6739. else
  6740. {
  6741. tempIndex = gun_index;
  6742. }
  6743. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6744. {
  6745. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6746. {
  6747. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6748. }
  6749. } // END OF FOR
  6750. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6751. }
  6752. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6753. {
  6754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6755. {
  6756. tempIndex = ((gun_index==2) ? 1: 0);
  6757. }
  6758. else
  6759. {
  6760. tempIndex = gun_index;
  6761. }
  6762. for (int index = 0; index < CCS_QUANTITY; index++)
  6763. {
  6764. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6765. {
  6766. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6767. }
  6768. }
  6769. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6770. }
  6771. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6772. {
  6773. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6774. {
  6775. tempIndex = ((gun_index==2) ? 1: 0);
  6776. }
  6777. else
  6778. {
  6779. tempIndex = gun_index;
  6780. }
  6781. for (int index = 0; index < GB_QUANTITY; index++)
  6782. {
  6783. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6784. {
  6785. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6786. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6787. }
  6788. }
  6789. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6790. }
  6791. else if(gunType[gun_index] == GUN_TYPE_DO)
  6792. {
  6793. tempIndex = gun_index;
  6794. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6795. {
  6796. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6797. {
  6798. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6799. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6800. }
  6801. }
  6802. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6803. }
  6804. else
  6805. {
  6806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6807. {
  6808. tempIndex = 2;
  6809. }
  6810. else
  6811. {
  6812. tempIndex = gun_index;
  6813. }
  6814. for (int index = 0; index < AC_QUANTITY; index++)
  6815. {
  6816. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6817. {
  6818. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6819. }
  6820. }
  6821. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6822. }
  6823. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6824. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6825. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6826. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6827. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6828. }
  6829. //***********************************************(5)VOLTAGE L1******************************************************/
  6830. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6831. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6832. (dataType == ReadingContext_Trigger))
  6833. {
  6834. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6835. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6836. {
  6837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6838. {
  6839. tempIndex = ((gun_index==2) ? 1: 0);
  6840. }
  6841. else
  6842. {
  6843. tempIndex = gun_index;
  6844. }
  6845. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6846. {
  6847. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6848. {
  6849. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6850. }
  6851. }
  6852. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6853. }
  6854. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6855. {
  6856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6857. {
  6858. tempIndex = ((gun_index==2) ? 1: 0);
  6859. }
  6860. else
  6861. {
  6862. tempIndex = gun_index;
  6863. }
  6864. for (int index = 0; index < CCS_QUANTITY; index++)
  6865. {
  6866. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6867. {
  6868. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6869. }
  6870. }
  6871. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6872. }
  6873. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6874. {
  6875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6876. {
  6877. tempIndex = ((gun_index==2) ? 1: 0);
  6878. }
  6879. else
  6880. {
  6881. tempIndex = gun_index;
  6882. }
  6883. for (int index = 0; index < GB_QUANTITY; index++)
  6884. {
  6885. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6886. {
  6887. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6888. }
  6889. }
  6890. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6891. }
  6892. else if(gunType[gun_index] == GUN_TYPE_DO)
  6893. {
  6894. tempIndex = gun_index;
  6895. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6896. {
  6897. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6898. {
  6899. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6900. }
  6901. }
  6902. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6903. }
  6904. else
  6905. {
  6906. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6907. {
  6908. tempIndex = 2;
  6909. }
  6910. else
  6911. {
  6912. tempIndex = gun_index;
  6913. }
  6914. for (int index = 0; index < AC_QUANTITY; index++)
  6915. {
  6916. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6917. {
  6918. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6919. }
  6920. }
  6921. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6922. }
  6923. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6924. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6925. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6926. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6927. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6928. }
  6929. //***********************************************(6)SOC******************************************************/
  6930. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6931. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6932. (dataType == ReadingContext_Trigger))
  6933. {
  6934. 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))
  6935. {
  6936. //idx_sample=5;
  6937. //sampledValue = NULL;
  6938. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6939. {
  6940. tempIndex = ((gun_index==2) ? 1: 0);
  6941. }
  6942. else
  6943. {
  6944. tempIndex = gun_index;
  6945. }
  6946. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6947. {
  6948. //tempIndex = ((gun_index==2) ? 1: 0);
  6949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6950. {
  6951. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6952. {
  6953. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6954. }
  6955. }
  6956. }
  6957. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6958. {
  6959. //tempIndex = ((gun_index==2) ? 1: 0);
  6960. for (int index = 0; index < CCS_QUANTITY; index++)
  6961. {
  6962. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6963. {
  6964. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6965. }
  6966. }
  6967. }
  6968. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6969. {
  6970. //tempIndex = ((gun_index==2) ? 1: 0);
  6971. for (int index = 0; index < GB_QUANTITY; index++)
  6972. {
  6973. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6974. {
  6975. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6976. }
  6977. }
  6978. }
  6979. else if(gunType[gun_index] == GUN_TYPE_DO)
  6980. {
  6981. //tempIndex = ((gun_index==2) ? 1: 0);
  6982. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6983. {
  6984. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6985. {
  6986. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6987. }
  6988. }
  6989. }
  6990. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6991. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6992. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6993. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6994. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6995. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6996. }
  6997. }
  6998. //********************************(7)Current.Import L2************************************************/
  6999. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7000. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7001. (dataType == ReadingContext_Trigger))
  7002. {
  7003. // Only for AC 3 phase
  7004. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7005. {
  7006. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7007. {
  7008. tempIndex = 2;
  7009. }
  7010. else
  7011. {
  7012. tempIndex = gun_index;
  7013. }
  7014. for (int index = 0; index < AC_QUANTITY; index++)
  7015. {
  7016. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7017. {
  7018. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7019. }
  7020. }
  7021. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7022. }
  7023. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7024. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7025. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7026. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7027. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7028. }
  7029. //********************************(8)Current.Import L3************************************************/
  7030. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7031. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7032. (dataType == ReadingContext_Trigger))
  7033. {
  7034. // Only for AC 3 phase
  7035. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7036. {
  7037. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7038. {
  7039. tempIndex = 2;
  7040. }
  7041. else
  7042. {
  7043. tempIndex = gun_index;
  7044. }
  7045. for (int index = 0; index < AC_QUANTITY; index++)
  7046. {
  7047. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7048. {
  7049. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7050. }
  7051. }
  7052. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7053. }
  7054. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7055. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7056. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7057. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7058. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7059. }
  7060. //***********************************************(9)VOLTAGE L2******************************************************/
  7061. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7062. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7063. (dataType == ReadingContext_Trigger))
  7064. {
  7065. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7066. {
  7067. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7068. {
  7069. tempIndex = 2;
  7070. }
  7071. else
  7072. {
  7073. tempIndex = gun_index;
  7074. }
  7075. for (int index = 0; index < AC_QUANTITY; index++)
  7076. {
  7077. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7078. {
  7079. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7080. }
  7081. }
  7082. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7083. }
  7084. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7085. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7086. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7087. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7088. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7089. }
  7090. //***********************************************(10)VOLTAGE L3******************************************************/
  7091. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7092. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7093. (dataType == ReadingContext_Trigger))
  7094. {
  7095. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7096. {
  7097. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7098. {
  7099. tempIndex = 2;
  7100. }
  7101. else
  7102. {
  7103. tempIndex = gun_index;
  7104. }
  7105. for (int index = 0; index < AC_QUANTITY; index++)
  7106. {
  7107. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7108. {
  7109. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7110. }
  7111. }
  7112. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7113. }
  7114. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7115. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7116. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7117. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7118. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7119. }
  7120. //***********************************************(11)Current.Offered******************************************************/
  7121. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7122. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7123. (dataType == ReadingContext_Trigger))
  7124. {
  7125. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7126. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7127. {
  7128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7129. {
  7130. tempIndex = ((gun_index==2) ? 1: 0);
  7131. }
  7132. else
  7133. {
  7134. tempIndex = gun_index;
  7135. }
  7136. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7137. {
  7138. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7139. {
  7140. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  7141. }
  7142. } // END OF FOR CHAdeMO_QUANTITY
  7143. }
  7144. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7145. {
  7146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7147. {
  7148. tempIndex = ((gun_index==2) ? 1: 0);
  7149. }
  7150. else
  7151. {
  7152. tempIndex = gun_index;
  7153. }
  7154. for (int index = 0; index < CCS_QUANTITY; index++)
  7155. {
  7156. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7157. {
  7158. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  7159. }
  7160. } // END OF CCS_QUANTITY
  7161. }
  7162. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7163. {
  7164. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7165. {
  7166. tempIndex = ((gun_index==2) ? 1: 0);
  7167. }
  7168. else
  7169. {
  7170. tempIndex = gun_index;
  7171. }
  7172. for (int index = 0; index < GB_QUANTITY; index++)
  7173. {
  7174. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7175. {
  7176. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  7177. }
  7178. } // END OF GB_QUANTITY
  7179. }
  7180. else if(gunType[gun_index] == GUN_TYPE_DO)
  7181. {
  7182. tempIndex = gun_index;
  7183. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7184. {
  7185. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7186. {
  7187. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  7188. }
  7189. }
  7190. }
  7191. else
  7192. {
  7193. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7194. {
  7195. tempIndex = 2;
  7196. }
  7197. else
  7198. {
  7199. tempIndex = gun_index;
  7200. }
  7201. for (int index = 0; index < AC_QUANTITY; index++)
  7202. {
  7203. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7204. {
  7205. uint16_t currentOffer;
  7206. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7207. {
  7208. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7209. }
  7210. else
  7211. {
  7212. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7213. }
  7214. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7215. }
  7216. }
  7217. }
  7218. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7219. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7220. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7221. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7222. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7223. }
  7224. //***********************************************(12)Power.Offered******************************************************/
  7225. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7226. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7227. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7228. {
  7229. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7230. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7231. {
  7232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7233. {
  7234. tempIndex = ((gun_index==2) ? 1: 0);
  7235. }
  7236. else
  7237. {
  7238. tempIndex = gun_index;
  7239. }
  7240. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7241. {
  7242. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7243. {
  7244. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7245. }
  7246. } // END OF FOR CHAdeMO_QUANTITY
  7247. }
  7248. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7249. {
  7250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7251. {
  7252. tempIndex = ((gun_index==2) ? 1: 0);
  7253. }
  7254. else
  7255. {
  7256. tempIndex = gun_index;
  7257. }
  7258. for (int index = 0; index < CCS_QUANTITY; index++)
  7259. {
  7260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7261. {
  7262. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7263. }
  7264. } // END OF CCS_QUANTITY
  7265. }
  7266. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7267. {
  7268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7269. {
  7270. tempIndex = ((gun_index==2) ? 1: 0);
  7271. }
  7272. else
  7273. {
  7274. tempIndex = gun_index;
  7275. }
  7276. for (int index = 0; index < GB_QUANTITY; index++)
  7277. {
  7278. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7279. {
  7280. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7281. }
  7282. } // END OF GB_QUANTITY
  7283. }
  7284. else if(gunType[gun_index] == GUN_TYPE_DO)
  7285. {
  7286. tempIndex = gun_index;
  7287. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7288. {
  7289. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7290. {
  7291. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7292. }
  7293. }
  7294. }
  7295. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7296. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7297. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7298. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7299. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7300. }
  7301. // Message create ====================================================================================================
  7302. if(TRUE)
  7303. {
  7304. json_object *MeterValueReq = json_object_new_object();
  7305. json_object *MeterValues = json_object_new_array();
  7306. json_object *sampledValues = json_object_new_array();
  7307. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7308. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7309. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7310. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7311. {
  7312. json_object *MeterValue = json_object_new_object();
  7313. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7314. {
  7315. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7316. {
  7317. json_object *sampledValue = json_object_new_object();
  7318. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7319. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7320. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7321. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7322. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7323. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7324. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7325. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7326. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7327. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7328. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7329. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7330. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7331. json_object_array_add(sampledValues, sampledValue);
  7332. }
  7333. }
  7334. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7335. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7336. json_object_array_add(MeterValues, MeterValue);
  7337. }
  7338. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7339. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7340. ,gun_index + 1
  7341. ,MESSAGE_TYPE_CALL
  7342. ,guid
  7343. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7344. json_object_put(MeterValueReq);
  7345. }
  7346. // Put request guid to hash map
  7347. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7348. 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*/)
  7349. {
  7350. result = PASS;
  7351. //DEBUG_INFO("MeterValues mapitem pass\n");
  7352. }
  7353. if((dataType != ReadingContext_Trigger) &&
  7354. (dataType != ReadingContext_Sample_Clock) &&
  7355. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7356. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7357. else
  7358. {
  7359. if(FirstHeartBeat)
  7360. LWS_Send(queuedata +2);
  7361. }
  7362. return result;
  7363. }
  7364. int sendLogStatusNotificationRequest(char *status)
  7365. {
  7366. mtrace();
  7367. int result = PASS;
  7368. char message[4096]={0};
  7369. char guid[37]={0};
  7370. char tempdata[128]={0};
  7371. json_object *LogStatusNotification = json_object_new_object();
  7372. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7373. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7374. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7375. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7376. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7377. random_uuid(guid);
  7378. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7379. json_object_put(LogStatusNotification);
  7380. LWS_Send(message);
  7381. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7382. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7383. {
  7384. result = PASS;
  7385. }
  7386. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7387. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7388. return result;
  7389. }
  7390. int sendSecurityEventNotificationRequest()
  7391. {
  7392. mtrace();
  7393. int result = PASS;
  7394. char message[4096]={0};
  7395. char guid[37]={0};
  7396. char tempdata[128]={0};
  7397. json_object *SecurityEventNotification = json_object_new_object();
  7398. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7399. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7400. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7401. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7402. random_uuid(guid);
  7403. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7404. json_object_put(SecurityEventNotification);
  7405. LWS_Send(message);
  7406. sprintf(tempdata, "SecurityEventNotification,0");
  7407. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7408. {
  7409. result = PASS;
  7410. }
  7411. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7412. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7413. return result;
  7414. }
  7415. int sendSignCertificateRequest()
  7416. {
  7417. mtrace();
  7418. int result = PASS;
  7419. char message[4096]={0};
  7420. char guid[37]={0};
  7421. char tempdata[128]={0};
  7422. json_object *SignCertificate = json_object_new_object();
  7423. DEBUG_INFO("sendSignCertificateRequest...\n");
  7424. // Read csr file content
  7425. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7426. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7427. char *line = NULL;
  7428. size_t len = 0;
  7429. while(getline(&line, &len, fp) != -1)
  7430. {
  7431. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7432. {
  7433. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7434. }
  7435. }
  7436. fclose(fp);
  7437. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7438. random_uuid(guid);
  7439. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7440. json_object_put(SignCertificate);
  7441. LWS_Send(message);
  7442. sprintf(tempdata, "SignCertificate,0");
  7443. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7444. {
  7445. result = PASS;
  7446. }
  7447. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7448. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7449. return result;
  7450. }
  7451. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7452. {
  7453. mtrace();
  7454. int result = PASS;
  7455. char message[110]={0};
  7456. char guid[37]={0};
  7457. char tempdata[65]={0};
  7458. json_object *FirmwareStatusNotification = json_object_new_object();
  7459. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7460. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7461. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7462. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7463. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7464. random_uuid(guid);
  7465. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7466. json_object_put(FirmwareStatusNotification);
  7467. LWS_Send(message);
  7468. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7469. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7470. {
  7471. result = PASS;
  7472. }
  7473. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7474. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7475. return result;
  7476. }
  7477. //==========================================
  7478. // send confirm routine
  7479. //==========================================
  7480. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7481. {
  7482. mtrace();
  7483. int result = FAIL;
  7484. char message[100]={0};
  7485. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7486. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7487. LWS_Send(message);
  7488. result = TRUE;
  7489. return result;
  7490. }
  7491. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7492. {
  7493. mtrace();
  7494. int result = FAIL;
  7495. char message[100]={0};
  7496. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7497. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7498. LWS_Send(message);
  7499. result = TRUE;
  7500. return result;
  7501. }
  7502. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7503. {
  7504. mtrace();
  7505. int result = FAIL;
  7506. char message[100]={0};
  7507. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7508. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7509. LWS_Send(message);
  7510. result = TRUE;
  7511. return result;
  7512. }
  7513. int sendClearCacheConfirmation(char *uuid,char *payload)
  7514. {
  7515. mtrace();
  7516. int result = FAIL;
  7517. char message[500]={0};
  7518. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7519. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7520. LWS_Send(message);
  7521. return result;
  7522. }
  7523. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7524. {
  7525. mtrace();
  7526. int result = FAIL;
  7527. char message[500]={0};
  7528. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7529. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7530. LWS_Send(message);
  7531. return result;
  7532. }
  7533. int sendDataTransferConfirmation(char *uuid,char *payload)
  7534. {
  7535. mtrace();
  7536. char statusStr[20]={0};
  7537. char dataStr[10]={0};
  7538. char sstr[20]={0};
  7539. int c = 0;
  7540. char *loc;
  7541. int result = FAIL;
  7542. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7543. /**********************status**************************/
  7544. loc = strstr(payload, "status");
  7545. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7546. c = 0;
  7547. while (loc[3+strlen("status")+c] != '\"')
  7548. {
  7549. sstr[c] = loc[3+strlen("status")+c];
  7550. c++;
  7551. }
  7552. sstr[c] = '\0';
  7553. strcpy(statusStr, sstr);
  7554. /**********************data**************************/
  7555. loc = strstr(payload, "data");
  7556. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7557. c = 0;
  7558. while (loc[3+strlen("data")+c] != '\"')
  7559. {
  7560. sstr[c] = loc[3+strlen("data")+c];
  7561. c++;
  7562. }
  7563. sstr[c] = '\0';
  7564. strcpy(dataStr, sstr);
  7565. return result;
  7566. }
  7567. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7568. {
  7569. mtrace();
  7570. int result = FAIL;
  7571. char message[1000]={0};
  7572. int CompositeScheduleIndex = 0;
  7573. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7574. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7575. if(nPeriod == 0)
  7576. {
  7577. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7578. {
  7579. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7580. ,MESSAGE_TYPE_CALLRESULT
  7581. ,uuid
  7582. ,payload
  7583. ,connectorIdInt);
  7584. }
  7585. else
  7586. {
  7587. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7588. ,MESSAGE_TYPE_CALLRESULT
  7589. ,uuid
  7590. ,payload
  7591. ,connectorIdInt
  7592. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7593. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7594. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7595. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7596. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7597. }
  7598. }
  7599. else
  7600. {
  7601. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7602. ,MESSAGE_TYPE_CALLRESULT
  7603. ,uuid
  7604. ,payload
  7605. ,connectorIdInt
  7606. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7607. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7608. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7609. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7610. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7611. {
  7612. if (idx_sample == 0)
  7613. {
  7614. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7615. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7616. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7617. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7618. }
  7619. else
  7620. {
  7621. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7622. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7623. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7624. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7625. }
  7626. }
  7627. sprintf(message + strlen(message), "]}}]");
  7628. }
  7629. LWS_Send(message);
  7630. result = TRUE;
  7631. return result;
  7632. }
  7633. int sendGetConfigurationConfirmation(char *uuid)
  7634. {
  7635. mtrace();
  7636. int result = FAIL;
  7637. int MaxKeySupported = 0;
  7638. int sentConfigurationNumber= 0;
  7639. int sentunConfigurationNumber= 0;
  7640. char message[1024*10]={0};
  7641. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7642. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7643. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7644. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7645. ,MESSAGE_TYPE_CALLRESULT
  7646. ,uuid );
  7647. //configuration key
  7648. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7649. {
  7650. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7651. {
  7652. if (sentConfigurationNumber == 0)
  7653. {
  7654. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7655. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7656. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7657. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7658. }
  7659. else
  7660. {
  7661. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7662. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7663. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7664. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7665. }
  7666. sentConfigurationNumber = sentConfigurationNumber + 1;
  7667. }
  7668. }
  7669. sprintf(message + strlen(message), "]");
  7670. if(UnknownKeynum != 0)
  7671. {
  7672. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7673. //unkown key
  7674. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7675. {
  7676. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7677. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7678. if(sentunConfigurationNumber == 0)
  7679. {
  7680. sprintf(message + strlen(message), "\"%s\""
  7681. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7682. }
  7683. else
  7684. {
  7685. sprintf(message + strlen(message), ",\"%s\""
  7686. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7687. }
  7688. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7689. }
  7690. sprintf(message + strlen(message), "]");
  7691. }
  7692. sprintf(message + strlen(message), "}]");
  7693. LWS_Send(message);
  7694. return result;
  7695. }
  7696. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7697. {
  7698. mtrace();
  7699. int result = FAIL;
  7700. char message[400]={0};
  7701. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7702. if(strcmp(payload,"")==0)
  7703. {
  7704. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7705. }
  7706. else
  7707. {
  7708. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7709. }
  7710. LWS_Send(message);
  7711. result = TRUE;
  7712. return result;
  7713. }
  7714. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7715. {
  7716. mtrace();
  7717. int result = FAIL;
  7718. char message[80]={0};
  7719. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7720. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7721. LWS_Send(message);
  7722. result = TRUE;
  7723. return result;
  7724. }
  7725. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7726. {
  7727. mtrace();
  7728. int result = FAIL;
  7729. char message[80]={0};
  7730. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7731. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7732. LWS_Send(message);
  7733. result = TRUE;
  7734. return result;
  7735. }
  7736. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7737. {
  7738. mtrace();
  7739. int result = FAIL;
  7740. char message[80]={0};
  7741. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7742. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7743. LWS_Send(message);
  7744. result = TRUE;
  7745. return result;
  7746. }
  7747. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7748. {
  7749. mtrace();
  7750. int result = FAIL;
  7751. char message[80]={0};
  7752. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7753. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7754. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7755. LWS_Send(message);
  7756. result = TRUE;
  7757. return result;
  7758. }
  7759. int sendResetConfirmation(char *uuid,char *payload)
  7760. {
  7761. mtrace();
  7762. int result = FAIL;
  7763. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7764. char message[80]={0};
  7765. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7766. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7767. LWS_Send(message);
  7768. result = TRUE;
  7769. return result;
  7770. }
  7771. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7772. {
  7773. mtrace();
  7774. int result = FAIL;
  7775. char message[500]={0};
  7776. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7777. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7778. LWS_Send(message);
  7779. result = TRUE;
  7780. return result;
  7781. }
  7782. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7783. {
  7784. mtrace();
  7785. int result = FAIL;
  7786. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7787. char message[80]={0};
  7788. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7789. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7790. LWS_Send(message);
  7791. result = TRUE;
  7792. return result;
  7793. }
  7794. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7795. {
  7796. mtrace();
  7797. int result = FAIL;
  7798. char message[80]={0};
  7799. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7800. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7801. LWS_Send(message);
  7802. result = TRUE;
  7803. return result;
  7804. }
  7805. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7806. {
  7807. mtrace();
  7808. int result = FAIL;
  7809. char message[80]={0};
  7810. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7811. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7812. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7813. LWS_Send(message);
  7814. result = TRUE;
  7815. return result;
  7816. }
  7817. int sendUpdateFirmwareConfirmation(char *uuid)
  7818. {
  7819. mtrace();
  7820. int result = FAIL;
  7821. char message[60]={0};
  7822. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7823. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7824. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7825. LWS_Send(message);
  7826. result = TRUE;
  7827. return result;
  7828. }
  7829. int sendCertificateSignedConfirmation(char *uuid)
  7830. {
  7831. mtrace();
  7832. int result = PASS;
  7833. char message[4096]={0};
  7834. json_object *CertificateSigned = json_object_new_object();
  7835. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7836. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7837. sprintf(message,"[%d,\"%s\",%s]"
  7838. ,MESSAGE_TYPE_CALLRESULT
  7839. ,uuid
  7840. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7841. json_object_put(CertificateSigned);
  7842. LWS_Send(message);
  7843. return result;
  7844. }
  7845. int sendDeleteCertificateConfirmation(char *uuid)
  7846. {
  7847. mtrace();
  7848. int result = PASS;
  7849. char message[4096]={0};
  7850. json_object *DeleteCertificate = json_object_new_object();
  7851. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7852. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7853. sprintf(message,"[%d,\"%s\",%s]"
  7854. ,MESSAGE_TYPE_CALLRESULT
  7855. ,uuid
  7856. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7857. json_object_put(DeleteCertificate);
  7858. LWS_Send(message);
  7859. return result;
  7860. }
  7861. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7862. {
  7863. mtrace();
  7864. int result = PASS;
  7865. char message[4096]={0};
  7866. json_object *ExtendedTriggerMessage = json_object_new_object();
  7867. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7868. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7869. sprintf(message,"[%d,\"%s\",%s]"
  7870. ,MESSAGE_TYPE_CALLRESULT
  7871. ,uuid
  7872. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7873. json_object_put(ExtendedTriggerMessage);
  7874. LWS_Send(message);
  7875. return result;
  7876. }
  7877. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7878. {
  7879. mtrace();
  7880. int result = PASS;
  7881. char message[4096]={0};
  7882. json_object *GetInstalledCertificateIds = json_object_new_object();
  7883. json_object *certificateHashDataDatas = json_object_new_array();
  7884. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7885. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7886. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7887. {
  7888. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7889. {
  7890. json_object *certificateHashData = json_object_new_object();
  7891. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7892. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7893. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7894. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7895. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7896. }
  7897. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7898. }
  7899. else
  7900. {
  7901. json_object_put(certificateHashDataDatas);
  7902. }
  7903. sprintf(message,"[%d,\"%s\",%s]"
  7904. ,MESSAGE_TYPE_CALLRESULT
  7905. ,uuid
  7906. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7907. json_object_put(GetInstalledCertificateIds);
  7908. LWS_Send(message);
  7909. return result;
  7910. }
  7911. int sendGetLogConfirmation(char *uuid)
  7912. {
  7913. mtrace();
  7914. int result = PASS;
  7915. char message[4096]={0};
  7916. json_object *GetLog = json_object_new_object();
  7917. DEBUG_INFO("sendGetLogConfirmation...\n");
  7918. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7919. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7920. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7921. sprintf(message,"[%d,\"%s\",%s]"
  7922. ,MESSAGE_TYPE_CALLRESULT
  7923. ,uuid
  7924. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7925. json_object_put(GetLog);
  7926. LWS_Send(message);
  7927. return result;
  7928. }
  7929. int sendInstallCertificateConfirmation(char *uuid)
  7930. {
  7931. mtrace();
  7932. int result = PASS;
  7933. char message[4096]={0};
  7934. json_object *InstallCertificate = json_object_new_object();
  7935. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7936. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7937. sprintf(message,"[%d,\"%s\",%s]"
  7938. ,MESSAGE_TYPE_CALLRESULT
  7939. ,uuid
  7940. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7941. json_object_put(InstallCertificate);
  7942. LWS_Send(message);
  7943. return result;
  7944. }
  7945. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7946. {
  7947. mtrace();
  7948. int result = PASS;
  7949. char message[4096]={0};
  7950. json_object *SignedUpdateFirmware = json_object_new_object();
  7951. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7952. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7953. sprintf(message,"[%d,\"%s\",%s]"
  7954. ,MESSAGE_TYPE_CALLRESULT
  7955. ,uuid
  7956. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7957. json_object_put(SignedUpdateFirmware);
  7958. LWS_Send(message);
  7959. return result;
  7960. }
  7961. int sendUnknownConfirmation(char *uuid)
  7962. {
  7963. mtrace();
  7964. int result = PASS;
  7965. char message[256]={0};
  7966. DEBUG_INFO("sendUnknownConfirmation...\n");
  7967. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7968. LWS_Send(message);
  7969. return result;
  7970. }
  7971. //==========================================
  7972. // Handle server request routine Start
  7973. //==========================================
  7974. int handleCancelReservationRequest(char *uuid, char *payload)
  7975. {
  7976. mtrace();
  7977. int result = FAIL;
  7978. int gunNO = 0;
  7979. int reservationIdInt = -1;
  7980. char comfirmstr[20];
  7981. DEBUG_INFO("handleCancelReservationRequest...\n");
  7982. json_object *CancelReservation;
  7983. CancelReservation = json_tokener_parse(payload);
  7984. if(!is_error(CancelReservation))
  7985. {
  7986. // Required data
  7987. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7988. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7989. }
  7990. json_object_put(CancelReservation);
  7991. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7992. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7993. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7994. if(reservationIdInt != -1)
  7995. {
  7996. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7997. //check Transaction active
  7998. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7999. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8000. {
  8001. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8002. {
  8003. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8004. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8005. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8006. {
  8007. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8008. }
  8009. else
  8010. {
  8011. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8012. }
  8013. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8014. goto end;
  8015. }
  8016. }
  8017. for (int index = 0; index < CCS_QUANTITY; index++)
  8018. {
  8019. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8020. {
  8021. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8022. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8023. if(gunType[2] == GUN_TYPE_CCS)
  8024. {
  8025. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8026. }
  8027. else
  8028. {
  8029. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8030. }
  8031. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8032. goto end;
  8033. }
  8034. }
  8035. for (int index = 0; index < GB_QUANTITY; index++)
  8036. {
  8037. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8038. {
  8039. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8040. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8041. if(gunType[2] == GUN_TYPE_GBT)
  8042. {
  8043. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8044. }
  8045. else
  8046. {
  8047. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8048. }
  8049. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8050. goto end;
  8051. }
  8052. }
  8053. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8054. {
  8055. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8056. {
  8057. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8058. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8059. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8060. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8061. goto end;
  8062. }
  8063. }
  8064. for (int index = 0; index < AC_QUANTITY; index++)
  8065. {
  8066. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8067. {
  8068. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8069. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8070. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8071. {
  8072. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8073. }
  8074. else
  8075. {
  8076. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8077. }
  8078. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8079. goto end;
  8080. }
  8081. }
  8082. }
  8083. //The reservationId does NOT match the reservationId
  8084. sendCancelReservationConfirmation(uuid, comfirmstr);
  8085. end:
  8086. // Fill in ocpp packet uuid
  8087. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  8088. return result;
  8089. }
  8090. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8091. {
  8092. mtrace();
  8093. int result = FAIL;
  8094. int gunIndex = -1;
  8095. char typeStr[16]={0};
  8096. char comfirmstr[20];
  8097. int specificId = FALSE;
  8098. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8099. json_object *ChangeAvailability;
  8100. ChangeAvailability = json_tokener_parse(payload);
  8101. if(!is_error(ChangeAvailability))
  8102. {
  8103. // Required data
  8104. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8105. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8106. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8107. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8108. }
  8109. json_object_put(ChangeAvailability);
  8110. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8111. {
  8112. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8113. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8114. }
  8115. else if(gunIndex == 0)
  8116. {
  8117. for(int i=0; i < gunTotalNumber; i++)
  8118. {
  8119. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  8120. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  8121. }
  8122. }
  8123. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8124. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8125. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8126. {
  8127. specificId = TRUE;
  8128. }
  8129. if(specificId == FALSE)
  8130. goto end;
  8131. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8132. {
  8133. //----------------------gunIndex is 0 ------------------------------------------------//
  8134. if(gunIndex == 0)
  8135. {
  8136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8137. {
  8138. for(int i=0; i < gunTotalNumber; i++)
  8139. {
  8140. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8141. {
  8142. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8143. {
  8144. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8145. {
  8146. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8147. goto end;
  8148. }
  8149. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8150. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8151. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8152. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8153. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8154. {
  8155. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8156. goto end;
  8157. }
  8158. }
  8159. }//END FOR CHAdeMO_QUANTITY
  8160. for (int index = 0; index < CCS_QUANTITY; index++)
  8161. {
  8162. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8163. {
  8164. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8165. {
  8166. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8167. goto end;
  8168. }
  8169. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8170. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8171. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8172. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8173. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8174. {
  8175. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8176. goto end;
  8177. }
  8178. }
  8179. }//END FOR CCS_QUANTITY
  8180. for (int index = 0; index < GB_QUANTITY; index++)
  8181. {
  8182. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8183. {
  8184. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8185. {
  8186. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8187. goto end;
  8188. }
  8189. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8190. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8191. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8192. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8193. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8194. {
  8195. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8196. goto end;
  8197. }
  8198. }
  8199. }// END FOR GB_QUANTITY
  8200. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8201. {
  8202. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8203. {
  8204. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8205. {
  8206. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8207. goto end;
  8208. }
  8209. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8210. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8211. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8212. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8213. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8214. {
  8215. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8216. goto end;
  8217. }
  8218. }
  8219. }// END FOR GENERAL_GUN_QUANTITY
  8220. for (int index = 0; index < AC_QUANTITY; index++)
  8221. {
  8222. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8223. {
  8224. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8225. {
  8226. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8227. goto end;
  8228. }
  8229. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8230. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8231. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8232. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8233. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8234. {
  8235. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8236. goto end;
  8237. }
  8238. }
  8239. }//END FOR AC_QUANTITY
  8240. }// END FOR gunTotalNumber
  8241. }
  8242. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8243. {
  8244. for(int i=0; i < gunTotalNumber; i++)
  8245. {
  8246. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8247. {
  8248. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8249. goto end;
  8250. }
  8251. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8252. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8253. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8254. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8255. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8256. {
  8257. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8258. goto end;
  8259. }
  8260. }
  8261. }
  8262. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8263. goto end;
  8264. }
  8265. //----------------------gunIndex is not 0 ------------------------------------------------//
  8266. //check Transaction active
  8267. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8268. {
  8269. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8270. {
  8271. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8272. {
  8273. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8274. goto end;
  8275. }
  8276. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8277. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8278. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8279. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8280. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8281. {
  8282. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8283. goto end;
  8284. }
  8285. else
  8286. {
  8287. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8288. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8289. goto end;
  8290. }
  8291. }
  8292. }//END FOR CHAdeMO_QUANTITY
  8293. for (int index = 0; index < CCS_QUANTITY; index++)
  8294. {
  8295. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8296. {
  8297. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8298. {
  8299. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8300. goto end;
  8301. }
  8302. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8303. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8304. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8305. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8306. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8307. {
  8308. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8309. goto end;
  8310. }
  8311. else
  8312. {
  8313. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8314. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8315. goto end;
  8316. }
  8317. }
  8318. }//END FOR CCS_QUANTITY
  8319. for (int index = 0; index < GB_QUANTITY; index++)
  8320. {
  8321. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8322. {
  8323. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8324. {
  8325. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8326. goto end;
  8327. }
  8328. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8329. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8330. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8331. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8332. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8333. {
  8334. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8335. goto end;
  8336. }
  8337. else
  8338. {
  8339. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8340. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8341. goto end;
  8342. }
  8343. }
  8344. }// END FOR GB_QUANTITY
  8345. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8346. {
  8347. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8348. {
  8349. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8350. {
  8351. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8352. goto end;
  8353. }
  8354. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8355. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8356. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8357. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8358. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8359. {
  8360. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8361. goto end;
  8362. }
  8363. else
  8364. {
  8365. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8366. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8367. goto end;
  8368. }
  8369. }
  8370. }// END FOR GENERAL_GUN_QUANTITY
  8371. for (int index = 0; index < AC_QUANTITY; index++)
  8372. {
  8373. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8374. {
  8375. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8376. {
  8377. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8378. goto end;
  8379. }
  8380. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8381. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8382. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8383. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8384. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8385. {
  8386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8387. goto end;
  8388. }
  8389. else
  8390. {
  8391. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8392. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8393. goto end;
  8394. }
  8395. }
  8396. }//END FOR AC_QUANTITY
  8397. }//END FOR AvailabilityTypeStr[Inoperative]
  8398. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8399. {
  8400. //----------------------gunIndex is 0 ------------------------------------------------//
  8401. if(gunIndex == 0)
  8402. {
  8403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8404. {
  8405. for(int i=0; i < gunTotalNumber; i++)
  8406. {
  8407. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8408. {
  8409. 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
  8410. {
  8411. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8412. goto end;
  8413. }
  8414. }//END FOR CHAdeMO_QUANTITY
  8415. for (int index = 0; index < CCS_QUANTITY; index++)
  8416. {
  8417. 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
  8418. {
  8419. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8420. goto end;
  8421. }
  8422. }//END FOR CCS_QUANTITY
  8423. for (int index = 0; index < GB_QUANTITY; index++)
  8424. {
  8425. 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
  8426. {
  8427. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8428. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8429. goto end;
  8430. }
  8431. }// END FOR GB_QUANTITY
  8432. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8433. {
  8434. 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
  8435. {
  8436. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8437. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8438. goto end;
  8439. }
  8440. }// END FOR GENERAL_GUN_QUANTITY
  8441. for (int index = 0; index < AC_QUANTITY; index++)
  8442. {
  8443. 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
  8444. {
  8445. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8446. goto end;
  8447. }
  8448. }//END FOR CHAdeMO_QUANTITY
  8449. }// END FOR gunTotalNumber
  8450. }
  8451. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8452. {
  8453. for(int i=0; i < gunTotalNumber; i++)
  8454. {
  8455. for (int index = 0; index < AC_QUANTITY; index++)
  8456. {
  8457. 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
  8458. {
  8459. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8460. goto end;
  8461. }
  8462. }//END FOR CHAdeMO_QUANTITY
  8463. } // END FOR gunTotalNumber
  8464. }
  8465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8466. goto end;
  8467. }
  8468. //----------------------gunIndex is not 0 ------------------------------------------------//
  8469. //check Transaction active
  8470. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8471. {
  8472. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8473. {
  8474. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8475. goto end;
  8476. }
  8477. }//END FOR CHAdeMO_QUANTITY
  8478. for (int index = 0; index < CCS_QUANTITY; index++)
  8479. {
  8480. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8481. {
  8482. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8483. goto end;
  8484. }
  8485. }//END FOR CCS_QUANTITY
  8486. for (int index = 0; index < GB_QUANTITY; index++)
  8487. {
  8488. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8489. {
  8490. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8491. goto end;
  8492. }
  8493. }// END FOR GB_QUANTITY
  8494. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8495. {
  8496. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8497. {
  8498. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8499. goto end;
  8500. }
  8501. }// END FOR GENERAL_GUN_QUANTITY
  8502. for (int index = 0; index < AC_QUANTITY; index++)
  8503. {
  8504. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8505. {
  8506. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8507. goto end;
  8508. }
  8509. }//END FOR AC_QUANTITY
  8510. }//END FOR AvailabilityTypeStr[Operative]
  8511. end:
  8512. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8513. {
  8514. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8515. }
  8516. else
  8517. {
  8518. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8519. }
  8520. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8521. {
  8522. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8523. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8524. }
  8525. else if(gunIndex == 0)
  8526. {
  8527. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8528. {
  8529. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8530. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8531. }
  8532. }
  8533. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8534. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8535. return result;
  8536. }
  8537. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8538. {
  8539. mtrace();
  8540. int valueInvalid = NO;
  8541. int result = FAIL;
  8542. char keystr[40]={0};
  8543. char valuestr[501]={0}; //value should be limited in 500 bytes
  8544. char comfirmstr[20]={0};
  8545. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8546. json_object *ChangeConfiguration;
  8547. ChangeConfiguration = json_tokener_parse(payload);
  8548. if(!is_error(ChangeConfiguration))
  8549. {
  8550. // Required data
  8551. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8552. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8553. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8554. {
  8555. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8556. }
  8557. else
  8558. {
  8559. valueInvalid = YES;
  8560. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8561. }
  8562. }
  8563. json_object_put(ChangeConfiguration);
  8564. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8565. {
  8566. DEBUG_ERROR("Payload is null or not accepted.\n");
  8567. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8568. }
  8569. else
  8570. {
  8571. int status = setKeyValue(keystr, valuestr);
  8572. switch(status)
  8573. {
  8574. case ConfigurationStatus_Accepted:
  8575. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8576. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8577. StoreConfigurationTable();
  8578. break;
  8579. case RebootRequired:
  8580. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8581. StoreConfigurationTable();
  8582. break;
  8583. case NotSupported:
  8584. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8585. break;
  8586. case ConfigurationStatus_Rejected:
  8587. default:
  8588. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8589. break;
  8590. }
  8591. }
  8592. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8593. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8594. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8595. {
  8596. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8597. SetOcppConnStatus(FALSE);
  8598. }
  8599. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8600. {
  8601. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8602. }
  8603. return result;
  8604. }
  8605. int handleClearCacheRequest(char *uuid, char *payload)
  8606. {
  8607. mtrace();
  8608. int result = FAIL;
  8609. char comfirmstr[20];
  8610. char rmFileCmd[100]={0};
  8611. struct stat stats;
  8612. DEBUG_INFO("handleClearCacheRequest...\n");
  8613. stat("/Storage/OCPP_PH", &stats);
  8614. // Check for directory existence
  8615. if (S_ISDIR(stats.st_mode) == 1)
  8616. {}
  8617. else
  8618. {
  8619. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8620. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8621. system(rmFileCmd);
  8622. }
  8623. if(OCPP_cleanLocalCache())
  8624. {
  8625. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8626. }
  8627. else
  8628. {
  8629. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8630. }
  8631. sendClearCacheConfirmation(uuid, comfirmstr);
  8632. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8633. return result;
  8634. }
  8635. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8636. {
  8637. mtrace();
  8638. int result = FAIL;
  8639. int resultRename;
  8640. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8641. char chargingProfilePurposeStr[26]={0};
  8642. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8643. char tempchargingProfilePurposeStr[26]={0};
  8644. char str[100]={0};
  8645. char fname[200]={0};
  8646. char comfirmstr[20]={0};
  8647. char word[1600]={0};
  8648. int clearflag = FALSE;
  8649. int chargingProfileIdIsNULL = FALSE;
  8650. int connectorIsNULL = FALSE;
  8651. int chargingProfilePurposeIsNULL = FALSE;
  8652. int stackLevelIsNULL = FALSE;
  8653. //int GotoEnd = FALSE;
  8654. FILE *fptr1, *fptr2;
  8655. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8656. int n_chargingProfile=0;
  8657. int isEmptyFile = FALSE;
  8658. char sLineWord[1600]={0};
  8659. char chargingProfiles[10][100]={0};
  8660. int ChargeProfileCount = 0;
  8661. int ch;
  8662. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8663. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8664. json_object *ClearChargingProfile;
  8665. ClearChargingProfile = json_tokener_parse(payload);
  8666. if(!is_error(ClearChargingProfile))
  8667. {
  8668. // Optional data
  8669. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8670. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8671. else
  8672. chargingProfileIdIsNULL = TRUE;
  8673. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8674. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8675. else
  8676. connectorIsNULL = TRUE;
  8677. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8678. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8679. else
  8680. chargingProfilePurposeIsNULL = TRUE;
  8681. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8682. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8683. else
  8684. stackLevelIsNULL = TRUE;
  8685. }
  8686. json_object_put(ClearChargingProfile);
  8687. if(connectorIdInt > 0)
  8688. {
  8689. if(chargingProfilePurposeIsNULL == TRUE)
  8690. {
  8691. int m = 0;
  8692. memset(fname, 0, ARRAY_SIZE(fname));
  8693. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8694. if((access(fname,F_OK))!=-1)
  8695. {
  8696. strcpy(chargingProfiles[m], fname);
  8697. m = m + 1;
  8698. }
  8699. memset(fname, 0, ARRAY_SIZE(fname));
  8700. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8701. if((access(fname,F_OK))!=-1)
  8702. {
  8703. strcpy(chargingProfiles[m], fname);
  8704. m = m + 1;
  8705. }
  8706. ChargeProfileCount = m;
  8707. }
  8708. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8709. {
  8710. //strcpy(fname, TxDefaultProfile_1_JSON);
  8711. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8712. if((access(fname,F_OK))!=-1)
  8713. {
  8714. strcpy(chargingProfiles[0], fname);
  8715. ChargeProfileCount = 1;
  8716. }
  8717. }
  8718. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8719. {
  8720. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8721. if((access(fname,F_OK))!=-1)
  8722. {
  8723. strcpy(chargingProfiles[0], fname);
  8724. ChargeProfileCount = 1;
  8725. }
  8726. //strcpy(fname, TxProfile_1_JSON);
  8727. }
  8728. }
  8729. else // Check all Charging Profiles
  8730. {
  8731. int i = 0;
  8732. char fnametemp[200]={0};
  8733. ChargeProfileCount = 0;
  8734. //Check ChargePointMaxProfile.json exit
  8735. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8736. {
  8737. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8738. i = i + 1;
  8739. }
  8740. //Check TxDefaultProfile_0.json exit
  8741. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8742. {
  8743. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8744. i = i + 1;
  8745. }
  8746. //Check TxDefaultProfile_%d.json
  8747. for(int j=1; j <= gunTotalNumber; j++)
  8748. {
  8749. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8750. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8751. if((access(fnametemp,F_OK))!=-1)
  8752. {
  8753. strcpy(chargingProfiles[i], fnametemp);
  8754. i = i + 1;
  8755. }
  8756. }
  8757. //Check TxProfile_%d.json
  8758. for(int j=1; j <= gunTotalNumber; j++)
  8759. {
  8760. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8761. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8762. if((access(fnametemp,F_OK))!=-1)
  8763. {
  8764. strcpy(chargingProfiles[i], fnametemp);
  8765. i = i + 1;
  8766. }
  8767. }
  8768. ChargeProfileCount = i;
  8769. }// End connectorIsNULL is TRUE
  8770. if(ChargeProfileCount == 0)
  8771. {
  8772. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8773. goto end;
  8774. }
  8775. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8776. {
  8777. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8778. goto end;
  8779. }
  8780. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8781. {
  8782. memset(str, 0, ARRAY_SIZE(str));
  8783. // clear temp file
  8784. sprintf(str,"rm -f %s",temp);
  8785. system(str);
  8786. for(int k=0; k < ChargeProfileCount; k++)
  8787. {
  8788. memset(str, 0, ARRAY_SIZE(str));
  8789. //clear file in C
  8790. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8791. system(str);
  8792. }
  8793. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8794. goto end;
  8795. }
  8796. else if(connectorIsNULL == TRUE)
  8797. {
  8798. for(int k=0; k < ChargeProfileCount; k++)
  8799. {
  8800. fptr1 = fopen(chargingProfiles[k], "r");
  8801. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8802. //Check Charging Profile Count
  8803. while(fscanf(fptr1, "%s", word) != EOF)
  8804. {
  8805. //DEBUG_INFO("word=%s\n",word);
  8806. if(strstr(word, "chargingProfileId")!= NULL)
  8807. {
  8808. //DEBUG_INFO("test chargingProfileId \n");
  8809. n_chargingProfile = n_chargingProfile + 1;
  8810. //DEBUG_INFO("chargingProfileId Found\n");
  8811. }
  8812. }
  8813. rewind(fptr1);
  8814. //search Charging Profile Element
  8815. //int i= 0;
  8816. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8817. {
  8818. json_object *tmpProfilee;
  8819. tmpProfilee = json_tokener_parse(sLineWord);
  8820. if(!is_error(tmpProfilee))
  8821. {
  8822. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8823. {
  8824. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8825. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8826. }
  8827. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8828. {
  8829. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8830. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8831. }
  8832. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8833. {
  8834. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8835. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8836. }
  8837. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8838. {
  8839. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8840. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8841. }
  8842. }
  8843. json_object_put(tmpProfilee);
  8844. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8845. {
  8846. //------- not write to fptr2-------//
  8847. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8848. //clearflag = TRUE;
  8849. }
  8850. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8851. {
  8852. //------- not write to fptr2-------//
  8853. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8854. }
  8855. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8856. {
  8857. //------- not write to fptr2-------//
  8858. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8859. }
  8860. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8861. {
  8862. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8863. }
  8864. else
  8865. {
  8866. fprintf(fptr2, sLineWord);//writing data into file
  8867. }
  8868. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8869. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8870. if(clearflag == TRUE)
  8871. {
  8872. fclose(fptr1);
  8873. fclose(fptr2);
  8874. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8875. system(str);
  8876. // clear temp file
  8877. sprintf(str,"rm -f %s",temp);
  8878. system(str);
  8879. }
  8880. else
  8881. {
  8882. fclose(fptr1);
  8883. fclose(fptr2);
  8884. memset(str, 0, ARRAY_SIZE(str));
  8885. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8886. system(str);
  8887. resultRename = rename(temp, chargingProfiles[k]);
  8888. if(resultRename == 0)
  8889. {
  8890. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8891. }
  8892. else
  8893. {
  8894. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8895. }
  8896. if(comfirmstr[0]== 0)
  8897. {
  8898. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8899. }
  8900. //Check chargingProfile is empty file
  8901. /*------ Read the file ----------------*/
  8902. fptr1=fopen(chargingProfiles[k],"r");
  8903. ch=fgetc(fptr1);
  8904. rewind(fptr1);
  8905. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8906. if(ch!=EOF)
  8907. {
  8908. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8909. {
  8910. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8911. if(sLineWord[0]=='\0')
  8912. {
  8913. isEmptyFile = TRUE;
  8914. break;
  8915. }
  8916. else
  8917. {
  8918. isEmptyFile = FALSE;
  8919. break;
  8920. }
  8921. }
  8922. }
  8923. else
  8924. isEmptyFile = TRUE;
  8925. fclose(fptr1);
  8926. if(isEmptyFile == TRUE)
  8927. {
  8928. memset(str, 0, ARRAY_SIZE(str));
  8929. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8930. system(str);
  8931. }
  8932. }
  8933. }// End of while(int k=0; k < ChargePointCount; k++)
  8934. }
  8935. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8936. {
  8937. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8938. for(int k=0; k < ChargeProfileCount; k++)
  8939. {
  8940. fptr1 = fopen(chargingProfiles[k], "r");
  8941. fptr2 = fopen(temp, "w+");
  8942. //Check Charging Profile Count
  8943. while(fscanf(fptr1, "%s", word) != EOF)
  8944. {
  8945. //DEBUG_INFO("word=%s\n",word);
  8946. if(strstr(word, "chargingProfileId")!= NULL)
  8947. {
  8948. n_chargingProfile = n_chargingProfile + 1;
  8949. }
  8950. }
  8951. rewind(fptr1);
  8952. //search Charging Profile Element
  8953. //int i= 0;
  8954. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8955. {
  8956. json_object *tmpProfilee;
  8957. tmpProfilee = json_tokener_parse(sLineWord);
  8958. if(!is_error(tmpProfilee))
  8959. {
  8960. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8961. {
  8962. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8963. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8964. }
  8965. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8966. {
  8967. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8968. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8969. }
  8970. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8971. {
  8972. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8973. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8974. }
  8975. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8976. {
  8977. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8978. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8979. }
  8980. }
  8981. json_object_put(tmpProfilee);
  8982. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8983. {
  8984. //------- not write to fptr2-------//
  8985. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8986. //clearflag = TRUE;
  8987. }
  8988. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8989. {
  8990. //------- not write to fptr2-------//
  8991. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8992. }
  8993. else if(stackLevelIsNULL == TRUE)
  8994. {
  8995. //Clear Whole File
  8996. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8997. clearflag = TRUE;
  8998. break;
  8999. }
  9000. else
  9001. {
  9002. fprintf(fptr2, sLineWord);//writing data into file
  9003. }
  9004. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9005. }
  9006. if(clearflag == TRUE)
  9007. {
  9008. fclose(fptr1);
  9009. fclose(fptr2);
  9010. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9011. system(str);
  9012. // clear temp file
  9013. sprintf(str,"rm -f %s",temp);
  9014. system(str);
  9015. }
  9016. else
  9017. {
  9018. fclose(fptr1);
  9019. fclose(fptr2);
  9020. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9021. system(str);
  9022. resultRename = rename(temp, chargingProfiles[k]);
  9023. if(resultRename == 0)
  9024. {
  9025. DEBUG_INFO("File ChargingProfile renamed successfully");
  9026. }
  9027. else
  9028. {
  9029. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9030. }
  9031. if(comfirmstr[0]== 0)
  9032. {
  9033. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9034. }
  9035. //Check chargingProfile is empty file
  9036. /*------ Read the file ----------------*/
  9037. fptr1=fopen(chargingProfiles[k],"r");
  9038. ch=fgetc(fptr1);
  9039. rewind(fptr1);
  9040. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9041. if(ch!=EOF)
  9042. {
  9043. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9044. {
  9045. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9046. if(sLineWord[0]=='\0')
  9047. {
  9048. isEmptyFile = TRUE;
  9049. break;
  9050. }
  9051. else
  9052. {
  9053. isEmptyFile = FALSE;
  9054. break;
  9055. }
  9056. }
  9057. }
  9058. else
  9059. isEmptyFile = TRUE;
  9060. fclose(fptr1);
  9061. if(isEmptyFile == TRUE)
  9062. {
  9063. memset(str, 0, ARRAY_SIZE(str));
  9064. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9065. system(str);
  9066. }
  9067. /*------- End of reading ---------------*/
  9068. }
  9069. } // while(int k=0; k < ChargeProfileCount; k++)
  9070. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9071. end:
  9072. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9073. {
  9074. if(connectorIdInt == 0)
  9075. {
  9076. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9077. {
  9078. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  9079. }
  9080. }
  9081. else
  9082. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  9083. }
  9084. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9085. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9086. return result;
  9087. }
  9088. void createFirmwareVersionByDataTransfer(void)
  9089. {
  9090. json_object *FirmwareDataTransfer = json_object_new_object();
  9091. // AC & DC model
  9092. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9093. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9094. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9095. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9096. // DC model
  9097. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9098. {
  9099. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9100. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9101. (gunType[3] != GUN_TYPE_UNKNOWN))
  9102. {
  9103. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9104. }
  9105. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9106. {
  9107. // DS DM DW
  9108. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9109. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9110. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9111. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9112. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9113. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9114. }
  9115. else
  9116. {
  9117. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9118. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9119. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9120. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9121. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9122. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9123. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9124. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9125. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9126. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9127. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9128. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9129. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9130. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9131. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9132. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9133. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9134. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9135. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9136. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9137. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9138. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9139. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9140. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9141. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9142. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9143. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9144. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9145. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9146. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9147. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9148. }
  9149. }
  9150. // 4G model
  9151. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9152. {
  9153. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9154. }
  9155. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9156. json_object_put(FirmwareDataTransfer);
  9157. }
  9158. int handleDataTransferRequest(char *uuid, char *payload)
  9159. {
  9160. mtrace();
  9161. json_object *response = json_object_new_object();
  9162. int result = FAIL;
  9163. char tempvendorId[255]={0};
  9164. char tempmessageId[50]={0};
  9165. char tempdata[1024]={0};
  9166. char message[2048]={0};
  9167. DEBUG_INFO("handleDataTransferRequest...\n");
  9168. if((uuid != NULL) && (payload != NULL))
  9169. {
  9170. json_object *DataTransfer;
  9171. DataTransfer = json_tokener_parse(payload);
  9172. if(!is_error(DataTransfer))
  9173. {
  9174. // Required data
  9175. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9176. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9177. // Optional data
  9178. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9179. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9180. if(json_object_object_get(DataTransfer, "data") != NULL)
  9181. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9182. result = PASS;
  9183. }
  9184. json_object_put(DataTransfer);
  9185. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9186. {
  9187. // Send all moudle firmware version on EVSE
  9188. createFirmwareVersionByDataTransfer();
  9189. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9190. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9191. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9192. json_object_put(response);
  9193. }
  9194. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9195. {
  9196. system("/usr/bin/run_tmate_restart.sh &");
  9197. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9198. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9199. json_object_put(response);
  9200. }
  9201. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9202. {
  9203. json_object *data;
  9204. data = json_tokener_parse(tempdata);
  9205. if(!is_error(data))
  9206. {
  9207. 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))
  9208. {
  9209. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9210. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9211. if(json_object_object_get(data, "SOC") != NULL)
  9212. {
  9213. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9214. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9215. }
  9216. if(json_object_object_get(data, "Energy") != NULL)
  9217. {
  9218. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9219. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9220. }
  9221. if(json_object_object_get(data, "Duration") != NULL)
  9222. {
  9223. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9224. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9225. }
  9226. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9227. }
  9228. else
  9229. {
  9230. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9231. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9232. }
  9233. }
  9234. else
  9235. {
  9236. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9237. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9238. }
  9239. json_object_put(data);
  9240. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9241. json_object_put(response);
  9242. }
  9243. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9244. {
  9245. json_object *data;
  9246. data = json_tokener_parse(tempdata);
  9247. if(!is_error(data))
  9248. {
  9249. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9250. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9251. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9252. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9253. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9254. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9255. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9256. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9257. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9258. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9259. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9260. }
  9261. else
  9262. {
  9263. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9264. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9265. }
  9266. json_object_put(data);
  9267. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9268. json_object_put(response);
  9269. }
  9270. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9271. {
  9272. json_object *data;
  9273. data = json_tokener_parse(tempdata);
  9274. if(!is_error(data))
  9275. {
  9276. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9277. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9278. if(json_object_object_get(data, "idToken") != NULL)
  9279. {
  9280. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9281. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9282. }
  9283. else
  9284. {
  9285. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9286. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9287. }
  9288. if(json_object_object_get(data, "price") != NULL) //v1.0
  9289. {
  9290. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9291. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9292. }
  9293. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9294. {
  9295. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9296. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9297. }
  9298. else
  9299. {
  9300. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9301. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9302. }
  9303. }
  9304. else
  9305. {
  9306. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9307. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9308. }
  9309. json_object_put(data);
  9310. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9311. json_object_put(response);
  9312. }
  9313. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9314. {
  9315. json_object *data;
  9316. data = json_tokener_parse(tempdata);
  9317. if(!is_error(data))
  9318. {
  9319. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9320. if(json_object_object_get(data, "txId") != NULL)
  9321. {
  9322. // California pricing V1.0
  9323. DEBUG_INFO("California pricing V1.0\n");
  9324. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9325. sprintf((char*)dmsVersion, "1.0");
  9326. for(int idx = 0;idx<gunTotalNumber;idx++)
  9327. {
  9328. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9329. {
  9330. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9331. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9332. if(json_object_object_get(data, "description") != NULL)
  9333. {
  9334. // California pricing V1.0
  9335. DEBUG_INFO("California pricing V1.0\n");
  9336. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9337. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9338. }
  9339. }
  9340. }
  9341. }
  9342. else if(json_object_object_get(data, "transactionId") != NULL)
  9343. {
  9344. // California pricing V2.0
  9345. DEBUG_INFO("California pricing V2.0\n");
  9346. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9347. sprintf((char*)dmsVersion, "2.0");
  9348. for(int idx=0;idx<gunTotalNumber;idx++)
  9349. {
  9350. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9351. {
  9352. if(json_object_object_get(data, "timestamp") != NULL)
  9353. {
  9354. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9355. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9356. }
  9357. else
  9358. {
  9359. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9360. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9361. }
  9362. if(json_object_object_get(data, "meterValue") != NULL)
  9363. {
  9364. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9365. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9366. }
  9367. else
  9368. {
  9369. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9370. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9371. }
  9372. if(json_object_object_get(data, "cost") != NULL)
  9373. {
  9374. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9375. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9376. }
  9377. else
  9378. {
  9379. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9380. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9381. }
  9382. if(json_object_object_get(data, "state") != NULL)
  9383. {
  9384. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9385. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9386. }
  9387. else
  9388. {
  9389. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9390. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9391. }
  9392. if(json_object_object_get(data, "chargingPrice") != NULL)
  9393. {
  9394. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9395. {
  9396. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9397. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9398. }
  9399. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9400. {
  9401. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9402. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9403. }
  9404. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9405. {
  9406. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9407. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9408. }
  9409. }
  9410. else
  9411. {
  9412. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9413. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9414. }
  9415. if(json_object_object_get(data, "idlePrice") != NULL)
  9416. {
  9417. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9418. {
  9419. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9420. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9421. }
  9422. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9423. {
  9424. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9425. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9426. }
  9427. }
  9428. if(json_object_object_get(data, "nextPeriod") != NULL)
  9429. {
  9430. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9431. {
  9432. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9433. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9434. }
  9435. else
  9436. {
  9437. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9438. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9439. }
  9440. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9441. {
  9442. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9443. {
  9444. 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")));
  9445. 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"));
  9446. }
  9447. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9448. {
  9449. 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")));
  9450. 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"));
  9451. }
  9452. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9453. {
  9454. 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")));
  9455. 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"));
  9456. }
  9457. }
  9458. else
  9459. {
  9460. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9461. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9462. }
  9463. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9464. {
  9465. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9466. {
  9467. 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")));
  9468. 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"));
  9469. }
  9470. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9471. {
  9472. 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")));
  9473. 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"));
  9474. }
  9475. }
  9476. }
  9477. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9478. {
  9479. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9480. {
  9481. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9482. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9483. }
  9484. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9485. {
  9486. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9487. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9488. }
  9489. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9490. {
  9491. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9492. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9493. }
  9494. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  9495. {
  9496. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9497. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9498. }
  9499. }
  9500. }
  9501. }
  9502. }
  9503. else
  9504. {
  9505. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9506. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9507. }
  9508. }
  9509. else
  9510. {
  9511. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9512. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9513. }
  9514. json_object_put(data);
  9515. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9516. json_object_put(response);
  9517. }
  9518. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9519. {
  9520. json_object *data;
  9521. data = json_tokener_parse(tempdata);
  9522. if(!is_error(data))
  9523. {
  9524. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9525. if(json_object_object_get(data, "txId") != NULL)
  9526. {
  9527. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9528. for(int idx = 0;idx<gunTotalNumber;idx++)
  9529. {
  9530. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9531. {
  9532. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9533. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9534. if(json_object_object_get(data, "description") != NULL)
  9535. {
  9536. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9537. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9538. }
  9539. else
  9540. {
  9541. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9542. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9543. }
  9544. }
  9545. }
  9546. }
  9547. else if(json_object_object_get(data, "transactionId") != NULL)
  9548. {
  9549. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9550. for(int idx = 0;idx<gunTotalNumber;idx++)
  9551. {
  9552. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9553. {
  9554. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9555. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9556. if(json_object_object_get(data, "cost") != NULL)
  9557. {
  9558. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  9559. ShmOCPP16DataPH->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9560. }
  9561. else
  9562. {
  9563. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9564. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9565. }
  9566. if(json_object_object_get(data, "priceText") != NULL)
  9567. {
  9568. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9569. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9570. }
  9571. else
  9572. {
  9573. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9574. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  9575. }
  9576. if(json_object_object_get(data, "qrCodeText") != NULL)
  9577. {
  9578. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9579. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9580. }
  9581. }
  9582. }
  9583. }
  9584. else
  9585. {
  9586. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9587. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9588. }
  9589. }
  9590. else
  9591. {
  9592. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9593. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9594. }
  9595. json_object_put(data);
  9596. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9597. json_object_put(response);
  9598. }
  9599. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9600. {
  9601. json_object *data;
  9602. data = json_tokener_parse(tempdata);
  9603. if(!is_error(data))
  9604. {
  9605. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9606. if(json_object_object_get(data, "Content_Type") != NULL)
  9607. {
  9608. 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))
  9609. {
  9610. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9611. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9612. {
  9613. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9614. }
  9615. }
  9616. else
  9617. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9618. }
  9619. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9620. }
  9621. else
  9622. {
  9623. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9624. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9625. }
  9626. json_object_put(data);
  9627. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9628. json_object_put(response);
  9629. }
  9630. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9631. {
  9632. json_object *data;
  9633. data = json_tokener_parse(tempdata);
  9634. if(!is_error(data))
  9635. {
  9636. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9637. if(json_object_object_get(data, "ConnectorId") != NULL)
  9638. {
  9639. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9640. }
  9641. if(json_object_object_get(data, "SerialNo") != NULL)
  9642. {
  9643. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9644. }
  9645. if(json_object_object_get(data, "Page_Index") != NULL)
  9646. {
  9647. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9648. }
  9649. if(json_object_object_get(data, "Duration") != NULL)
  9650. {
  9651. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9652. }
  9653. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9654. }
  9655. else
  9656. {
  9657. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9658. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9659. }
  9660. json_object_put(data);
  9661. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9662. json_object_put(response);
  9663. }
  9664. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9665. {
  9666. json_object *data;
  9667. data = json_tokener_parse(tempdata);
  9668. if(!is_error(data))
  9669. {
  9670. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9671. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9672. {
  9673. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9674. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9675. else
  9676. {
  9677. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9678. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9679. }
  9680. }
  9681. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9682. {
  9683. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9684. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9685. else
  9686. {
  9687. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9688. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9689. }
  9690. }
  9691. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9692. {
  9693. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9694. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  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. }
  9701. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9702. {
  9703. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9704. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9705. else
  9706. {
  9707. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9708. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9709. }
  9710. }
  9711. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9712. {
  9713. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9714. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  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, "OfflinePolicy") != NULL)
  9722. {
  9723. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9724. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9725. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9726. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9727. else
  9728. {
  9729. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9730. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9731. }
  9732. }
  9733. if(json_object_object_get(data, "isAuthentication") != NULL)
  9734. {
  9735. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9736. {
  9737. case 0:
  9738. case 1:
  9739. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9740. break;
  9741. default:
  9742. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9743. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9744. break;
  9745. }
  9746. }
  9747. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9748. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9749. }
  9750. else
  9751. {
  9752. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9753. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9754. }
  9755. json_object_put(data);
  9756. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9757. json_object_put(response);
  9758. }
  9759. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9760. {
  9761. json_object *data;
  9762. data = json_tokener_parse(tempdata);
  9763. if(!is_error(data))
  9764. {
  9765. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9766. if(json_object_object_get(data, "stationName") != NULL)
  9767. {
  9768. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9769. }
  9770. else
  9771. {
  9772. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9773. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9774. }
  9775. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9776. {
  9777. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9778. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9779. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9780. }
  9781. }
  9782. else
  9783. {
  9784. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9785. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9786. }
  9787. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9788. json_object_put(response);
  9789. }
  9790. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9791. {
  9792. json_object *data;
  9793. data = json_tokener_parse(tempdata);
  9794. if(!is_error(data))
  9795. {
  9796. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9797. if(json_object_object_get(data, "weatherId") != NULL)
  9798. {
  9799. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9800. }
  9801. else
  9802. {
  9803. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9804. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9805. }
  9806. if(json_object_object_get(data, "Temperature") != NULL)
  9807. {
  9808. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  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("temperature data can not get."));
  9814. }
  9815. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9816. {
  9817. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9818. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9819. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9820. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9821. }
  9822. }
  9823. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9824. {
  9825. json_object *data;
  9826. data = json_tokener_parse(tempdata);
  9827. if(!is_error(data))
  9828. {
  9829. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9830. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9831. {
  9832. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9833. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9834. }
  9835. else
  9836. {
  9837. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9838. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9839. }
  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("charger_info content got something wrong."));
  9845. }
  9846. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9847. json_object_put(response);
  9848. }
  9849. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9850. {
  9851. json_object *data;
  9852. data = json_tokener_parse(tempdata);
  9853. if(!is_error(data))
  9854. {
  9855. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9856. {
  9857. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9858. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9859. if(gun_index < gunTotalNumber)
  9860. {
  9861. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9862. {
  9863. json_object *responsedata = json_object_new_object();
  9864. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9865. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9866. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9867. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9868. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9869. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9870. }
  9871. else
  9872. {
  9873. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9874. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9875. }
  9876. }
  9877. else
  9878. {
  9879. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9880. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9881. }
  9882. }
  9883. else
  9884. {
  9885. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9886. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9887. }
  9888. }
  9889. else
  9890. {
  9891. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9892. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9893. }
  9894. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9895. json_object_put(response);
  9896. }
  9897. else
  9898. {
  9899. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9900. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9901. }
  9902. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9903. json_object_put(response);
  9904. }
  9905. else
  9906. {
  9907. // Can not find valid message id
  9908. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9909. }
  9910. }
  9911. else
  9912. {
  9913. // Payload is null
  9914. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9915. }
  9916. LWS_Send(message);
  9917. return result;
  9918. }
  9919. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9920. {
  9921. mtrace();
  9922. int result = FAIL;
  9923. int connectorIdInt, durationInt;
  9924. char chargingRateUnitStr[4]={0};
  9925. char comfirmstr[20];
  9926. int confirmPeriods = 0;
  9927. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9928. json_object *GetCompositeSchedule;
  9929. GetCompositeSchedule = json_tokener_parse(payload);
  9930. if(!is_error(GetCompositeSchedule))
  9931. {
  9932. // Required data
  9933. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9934. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9935. else
  9936. connectorIdInt = -1;
  9937. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9938. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9939. else
  9940. durationInt = 86400;
  9941. // Optional data
  9942. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9943. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9944. }
  9945. json_object_put(GetCompositeSchedule);
  9946. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9947. if((connectorIdInt == 0) ||
  9948. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9949. {
  9950. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9951. struct StructChargingProfile tmpProfile[1];
  9952. if(strstr(chargingRateUnitStr, "W") != NULL)
  9953. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9954. else
  9955. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9956. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9957. {
  9958. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9959. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9960. }
  9961. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9962. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9963. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9964. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9965. {
  9966. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9967. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9968. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9969. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9970. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9971. {
  9972. confirmPeriods = idx;
  9973. break;
  9974. }
  9975. }
  9976. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9977. {
  9978. confirmPeriods += 1;
  9979. }
  9980. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9981. }
  9982. else
  9983. {
  9984. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9985. }
  9986. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9987. return result;
  9988. }
  9989. int handleGetConfigurationRequest(char *uuid, char *payload)
  9990. {
  9991. mtrace();
  9992. int result = FAIL;
  9993. int MaxKeySupported = 0;
  9994. int n_keys = 0;
  9995. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9996. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9997. json_object *GetConfiguration;
  9998. GetConfiguration = json_tokener_parse(payload);
  9999. if(!is_error(GetConfiguration))
  10000. {
  10001. // Optional data
  10002. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10003. {
  10004. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10005. {
  10006. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10007. n_keys = idx + 1;
  10008. }
  10009. }
  10010. }
  10011. json_object_put(GetConfiguration);
  10012. UnknownKeynum = 0;
  10013. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10014. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10015. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10016. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10017. if(n_keys != 0)
  10018. {
  10019. for(int i=0;i<n_keys;i++)
  10020. {
  10021. getKeyValue(requestKey[i]);
  10022. }
  10023. }
  10024. else
  10025. {
  10026. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10027. getKeyValue("");
  10028. }
  10029. processUnkownKey();
  10030. sendGetConfigurationConfirmation(uuid);
  10031. return result;
  10032. }
  10033. static char fnamePlusPath[100]={0};
  10034. static char fnamePWithNoPath[60]={0};
  10035. void checkUploadLog(void)
  10036. {
  10037. FILE *fp;
  10038. /* Open the command for reading. */
  10039. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10040. if (fp == NULL) {
  10041. DEBUG_WARN("Failed to run command\n" );
  10042. exit(1);
  10043. }
  10044. int ftppathlen = 0;
  10045. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10046. int i = 0;
  10047. /* Read the output a line at a time - output it. */
  10048. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10049. if(i==0)
  10050. {
  10051. ftppathlen = strlen(fnamePlusPath);
  10052. DEBUG_INFO("%s\n", fnamePlusPath);
  10053. fnamePlusPath[ftppathlen]='\0';
  10054. break;
  10055. }
  10056. i= i+1;
  10057. }
  10058. /* close */
  10059. pclose(fp);
  10060. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10061. {
  10062. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10063. {
  10064. fnamePlusPath[k]='\0';
  10065. }
  10066. }
  10067. i=1;
  10068. //char fname[60]={0};
  10069. while(i < ftppathlen)
  10070. {
  10071. int len=ftppathlen-i;
  10072. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10073. {
  10074. DEBUG_INFO("compare '/' all right\n");
  10075. break;
  10076. }
  10077. i=i+1;
  10078. }
  10079. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10080. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10081. fnamePWithNoPath[i+1] = '\0';
  10082. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10083. {
  10084. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10085. {
  10086. fnamePWithNoPath[j]='\0';
  10087. }
  10088. }
  10089. FILE* fp1 = fopen(fnamePlusPath, "r");
  10090. if (fp1)
  10091. {
  10092. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10093. // file exists
  10094. fclose(fp1);
  10095. }
  10096. else
  10097. {
  10098. // file doesn't exist
  10099. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10100. }
  10101. }
  10102. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10103. {
  10104. mtrace();
  10105. int result = FAIL;
  10106. time_t CurrentTime;
  10107. struct tm *tm;
  10108. pthread_t th_Status;
  10109. CurrentTime = time(NULL);
  10110. tm = localtime(&CurrentTime);
  10111. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  10112. 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);
  10113. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10114. if(!interLock.isGetDiagnosticGoing)
  10115. {
  10116. interLock.isGetDiagnosticGoing = 1;
  10117. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10118. sleep(1);
  10119. }
  10120. else
  10121. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10122. return result;
  10123. }
  10124. void* GetDiagnosticsProcess(void* data)
  10125. {
  10126. pthread_detach(pthread_self());
  10127. mtrace();
  10128. int retriesInt=0, retryIntervalInt=0;
  10129. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10130. 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};
  10131. int port=0;
  10132. int isSuccess = FALSE;
  10133. char ftpbuf[200]={0};
  10134. char cmdBuf[2048];
  10135. struct tm *tmNow;
  10136. time_t CurrentTime;
  10137. struct tm tmStart;
  10138. struct tm tmStop;
  10139. CurrentTime = time(NULL);
  10140. tmNow=localtime(&CurrentTime);
  10141. uint16_t targetYear, targetMonth;
  10142. json_object *GetDiagnostics;
  10143. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10144. GetDiagnostics = json_tokener_parse(data);
  10145. if(!is_error(GetDiagnostics))
  10146. {
  10147. // Required data
  10148. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10149. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10150. // Optional data
  10151. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10152. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10153. else
  10154. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10155. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10156. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10157. else
  10158. retryIntervalInt = 30;
  10159. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10160. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10161. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10162. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10163. }
  10164. json_object_put(GetDiagnostics);
  10165. // Notify CSU to get log of dispensers.
  10166. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  10167. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  10168. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  10169. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  10170. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  10171. )
  10172. {
  10173. sprintf((char *)ShmOCPP16DataPH->GetDiagnostics.StartTime,"%s",startTimestr);
  10174. sprintf((char *)ShmOCPP16DataPH->GetDiagnostics.StopTime,"%s",stopTimestr);
  10175. ShmOCPP16DataPH->MsMsg.bits.GetDiagnosticsReq = TRUE;
  10176. struct timespec timerGetDiagnostics;
  10177. refreshStartTimer(&timerGetDiagnostics);
  10178. while(ShmOCPP16DataPH->MsMsg.bits.GetDiagnosticsReq != FALSE)
  10179. {
  10180. if(getDiffSecNow(timerGetDiagnostics)>=180)
  10181. {
  10182. ShmOCPP16DataPH->MsMsg.bits.GetDiagnosticsReq = FALSE;
  10183. DEBUG_INFO("Waiting log of dispenser timeout.");
  10184. }
  10185. }
  10186. }
  10187. // Pack log to compress file
  10188. 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) &&
  10189. (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))
  10190. {
  10191. // Pack system log
  10192. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10193. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10194. targetYear = tmStart.tm_year;
  10195. targetMonth = tmStart.tm_mon;
  10196. do
  10197. {
  10198. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10199. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10200. if(targetMonth+1>=13)
  10201. {
  10202. targetYear += 1;
  10203. targetMonth = 1;
  10204. }
  10205. else
  10206. {
  10207. targetMonth += 1;
  10208. }
  10209. }while((targetYear < (tmNow->tm_year+1900)) ||
  10210. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10211. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10212. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10213. sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
  10214. sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
  10215. sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
  10216. system(cmdBuf);
  10217. // Pack charging & event log
  10218. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10219. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10220. targetYear = tmStart.tm_year;
  10221. targetMonth = tmStart.tm_mon;
  10222. do
  10223. {
  10224. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10225. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  10226. if(targetMonth+1>=13)
  10227. {
  10228. targetYear += 1;
  10229. targetMonth = 1;
  10230. }
  10231. else
  10232. {
  10233. targetMonth += 1;
  10234. }
  10235. }while((targetYear < (tmNow->tm_year+1900)) ||
  10236. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10237. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10238. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10239. system(cmdBuf);
  10240. // Combine log file
  10241. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10242. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10243. }
  10244. else
  10245. {
  10246. system("exec /root/logPackTools 'log' 6");
  10247. }
  10248. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10249. system(cmdBuf);
  10250. checkUploadLog();
  10251. //****************location*******************/
  10252. if(strcmp(locationstr,"")==0)
  10253. {
  10254. DEBUG_INFO("location is <Empty>!\n");
  10255. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10256. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10257. goto end;
  10258. }
  10259. memset(protocol, 0, ARRAY_SIZE(protocol));
  10260. memset(user, 0, ARRAY_SIZE(user) );
  10261. memset(password, 0, ARRAY_SIZE(password));
  10262. memset(host, 0, ARRAY_SIZE(host));
  10263. memset(path, 0, ARRAY_SIZE(path));
  10264. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10265. memset(host1, 0, ARRAY_SIZE(host1));
  10266. memset(path1, 0, ARRAY_SIZE(path1));
  10267. /*location: ftp://user:password@host:port/path*/
  10268. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10269. if((access(fnamePlusPath,F_OK))!=-1)
  10270. {
  10271. DEBUG_INFO("fnamePlusPath exist.\n");
  10272. }
  10273. else
  10274. {
  10275. DEBUG_INFO("fnamePlusPath not exist!\n");
  10276. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10277. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10278. goto end;
  10279. }
  10280. if(strchr(locationstr,'@')==NULL)
  10281. {
  10282. sscanf(locationstr,
  10283. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10284. protocol, host, &port, path);
  10285. strcpy(user,"anonymous");
  10286. strcpy(password,"");
  10287. }
  10288. else
  10289. {
  10290. //DEBUG_INFO("pch=%s\n", pch);
  10291. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10292. protocol, user, password, host, &port, path);
  10293. }
  10294. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10295. {
  10296. DEBUG_INFO("protocol is not ftp/http ! \n");
  10297. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10298. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10299. goto end;
  10300. }
  10301. if(strncmp(locationstr,"http", 4) == 0)
  10302. {
  10303. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10304. sprintf(ftppath,"/%s", path);
  10305. do
  10306. {
  10307. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10308. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10309. sleep(3);
  10310. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10311. if(!isSuccess)
  10312. {
  10313. DEBUG_INFO("Diagnostics fail.\n");
  10314. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10315. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10316. sleep(retryIntervalInt);
  10317. }
  10318. else
  10319. {
  10320. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10321. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10322. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10323. }
  10324. retriesInt--;
  10325. }while((isSuccess == 0)&&(retriesInt >= 0));
  10326. }
  10327. else
  10328. {
  10329. sscanf(host,"%[^/]%s",host1, path1);
  10330. if(strlen(path) > 0)
  10331. sprintf(ftppath,"/%s", path);
  10332. else
  10333. sprintf(ftppath,"/%s", path1);
  10334. int ftppathlen=strlen(ftppath);
  10335. int i=1;
  10336. char filenametemp[50];
  10337. while(i < ftppathlen)
  10338. {
  10339. int len=ftppathlen-i;
  10340. if(ftppath[len]== 47) // '/' ascll code: 47
  10341. {
  10342. DEBUG_INFO("find '/' all right\n");
  10343. break;
  10344. }
  10345. i=i+1;
  10346. }
  10347. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10348. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10349. filenametemp[i+1] = 0;
  10350. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10351. if(port == 0)
  10352. port = 21;
  10353. do
  10354. {
  10355. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10356. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10357. sleep(3);
  10358. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10359. if(!isSuccess)
  10360. {
  10361. DEBUG_INFO("Diagnostics fail.\n");
  10362. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10363. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10364. sleep(retryIntervalInt);
  10365. }
  10366. else
  10367. {
  10368. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10369. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10370. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10371. }
  10372. retriesInt--;
  10373. }while((!isSuccess)&&(retriesInt >= 0));
  10374. }
  10375. end:
  10376. system("rm -f /mnt/*");
  10377. sleep(5);
  10378. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10379. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10380. interLock.isGetDiagnosticGoing = 0;
  10381. pthread_exit(NULL);
  10382. }
  10383. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10384. {
  10385. mtrace();
  10386. int result = FAIL;
  10387. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10388. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10389. {
  10390. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10391. locallistVersion = -1;
  10392. }
  10393. else
  10394. {
  10395. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10396. locallistVersion = 0;
  10397. OCPP_getListVerion();
  10398. }
  10399. //from db.OCPP_getListVerion
  10400. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10401. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10402. sendGetLocalListVersionConfirmation(uuid,"");
  10403. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10404. return result;
  10405. }
  10406. int handleRemoteStartRequest(char *uuid, char *payload)
  10407. {
  10408. mtrace();
  10409. int result = PASS;
  10410. int connectorIdInt=-1;
  10411. int tempIndex = 0;
  10412. char comfirmstr[20]={0};
  10413. char cmdBuf[512];
  10414. json_object *RemoteStartTransaction;
  10415. FILE *fp;
  10416. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10417. if(server_pending == TRUE)
  10418. {
  10419. result = FAIL;
  10420. }
  10421. RemoteStartTransaction = json_tokener_parse(payload);
  10422. if(!is_error(RemoteStartTransaction))
  10423. {
  10424. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10425. {
  10426. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10427. }
  10428. else
  10429. {
  10430. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10431. {
  10432. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10433. {
  10434. connectorIdInt = (gun_index+1);
  10435. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10436. break;
  10437. }
  10438. }
  10439. }
  10440. if(connectorIdInt == 0)
  10441. {
  10442. DEBUG_WARN("Connector id shall not equal 0.\n");
  10443. result = FAIL;
  10444. }
  10445. else if(connectorIdInt == -1)
  10446. {
  10447. DEBUG_INFO("Connector id does not specific.\n");
  10448. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10449. {
  10450. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10451. // Required data
  10452. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10453. // Optional data
  10454. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10455. {
  10456. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10457. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10458. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10459. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10460. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10461. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10462. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10463. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10464. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10465. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10466. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10467. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10468. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10469. {
  10470. 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")));
  10471. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10472. 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"));
  10473. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10474. 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"));
  10475. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10476. 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")));
  10477. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10478. {
  10479. 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++)
  10480. {
  10481. 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"));
  10482. 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"));
  10483. 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)
  10484. 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"));
  10485. }
  10486. }
  10487. }
  10488. }
  10489. else
  10490. {
  10491. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10492. }
  10493. }
  10494. }
  10495. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10496. {
  10497. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10498. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10499. // Required data
  10500. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10501. // Optional data
  10502. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10503. {
  10504. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10505. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10506. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10507. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10508. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10509. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10510. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10511. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10512. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10513. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10514. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10515. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10516. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10517. {
  10518. 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")));
  10519. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10520. 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"));
  10521. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10522. 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"));
  10523. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10524. 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")));
  10525. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10526. {
  10527. 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++)
  10528. {
  10529. 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"));
  10530. 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"));
  10531. 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)
  10532. 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"));
  10533. }
  10534. }
  10535. }
  10536. }
  10537. else
  10538. {
  10539. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10540. }
  10541. }
  10542. else
  10543. {
  10544. DEBUG_WARN("Connector id is over maximun value.\n");
  10545. result = FAIL;
  10546. }
  10547. }
  10548. if(result == PASS)
  10549. {
  10550. if(connectorIdInt > 0)
  10551. {
  10552. //check Transaction active
  10553. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10554. {
  10555. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10556. {
  10557. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10558. }
  10559. else
  10560. {
  10561. tempIndex = connectorIdInt -1;
  10562. }
  10563. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10564. {
  10565. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10566. {
  10567. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10568. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10569. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10570. {
  10571. //Reserved
  10572. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10573. }
  10574. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10575. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10576. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10577. {
  10578. //Reserved
  10579. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10580. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10581. goto end;
  10582. }
  10583. else
  10584. {
  10585. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10586. {
  10587. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10588. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10589. goto end;
  10590. }
  10591. }//END FOR ELSE
  10592. }
  10593. }// END FOR CHAdeMO_QUANTITY
  10594. }
  10595. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10596. {
  10597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10598. {
  10599. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10600. }
  10601. else
  10602. {
  10603. tempIndex = connectorIdInt -1;
  10604. }
  10605. for (int index = 0; index < CCS_QUANTITY; index++)
  10606. {
  10607. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10608. {
  10609. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10610. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10611. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10612. {
  10613. //Reserved
  10614. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10615. }
  10616. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10617. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10618. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10619. {
  10620. //Reserved
  10621. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10622. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10623. goto end;
  10624. }
  10625. else
  10626. {
  10627. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10628. {
  10629. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10630. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10631. goto end;
  10632. }
  10633. }// END FOR ELSE
  10634. }
  10635. }// END FOR CCS_QUANTITY
  10636. }
  10637. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10638. {
  10639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10640. {
  10641. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10642. }
  10643. else
  10644. {
  10645. tempIndex = connectorIdInt -1;
  10646. }
  10647. for (int index = 0; index < GB_QUANTITY; index++)
  10648. {
  10649. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10650. {
  10651. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10652. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10653. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10654. {
  10655. //Reserved
  10656. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10657. }
  10658. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10659. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10660. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10661. {
  10662. //Reserved
  10663. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10664. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10665. goto end;
  10666. }
  10667. else
  10668. {
  10669. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10670. {
  10671. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10672. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10673. goto end;
  10674. }
  10675. }// END FOR ELSE
  10676. }
  10677. } // END FOR GB_QUANTITY
  10678. }
  10679. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10680. {
  10681. tempIndex = connectorIdInt -1;
  10682. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10683. {
  10684. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10685. {
  10686. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10687. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10688. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10689. {
  10690. //Reserved
  10691. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10692. }
  10693. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10694. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10695. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10696. {
  10697. //Reserved
  10698. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10699. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10700. goto end;
  10701. }
  10702. else
  10703. {
  10704. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10705. {
  10706. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10707. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10708. goto end;
  10709. }
  10710. }// END FOR ELSE
  10711. }
  10712. } // END FOR GB_QUANTITY
  10713. }
  10714. else
  10715. {
  10716. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10717. {
  10718. tempIndex = 2;
  10719. }
  10720. else
  10721. {
  10722. tempIndex = connectorIdInt -1;
  10723. }
  10724. for (int index = 0; index < AC_QUANTITY; index++)
  10725. {
  10726. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10727. {
  10728. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10729. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10730. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10731. {
  10732. //Reserved
  10733. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10734. }
  10735. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10736. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10737. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10738. {
  10739. //Reserved
  10740. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10741. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10742. goto end;
  10743. }
  10744. else
  10745. {
  10746. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10747. {
  10748. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10749. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10750. goto end;
  10751. }
  10752. }//END FOR ELSE
  10753. }
  10754. }// END FOR AC_QUANTITY
  10755. }
  10756. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10757. {
  10758. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10759. {
  10760. // Save profile to file
  10761. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10762. system(cmdBuf);
  10763. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10764. fp = fopen(cmdBuf, "w");
  10765. 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));
  10766. fclose(fp);
  10767. }
  10768. else
  10769. {
  10770. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10771. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10772. goto end;
  10773. }
  10774. }
  10775. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10776. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10777. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10778. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10779. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10780. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10781. }
  10782. else
  10783. {
  10784. uint8_t isHasIdleConnector = FALSE;
  10785. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10786. {
  10787. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10788. {
  10789. isHasIdleConnector = TRUE;
  10790. break;
  10791. }
  10792. }
  10793. if((isHasIdleConnector == TRUE) && !ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10794. {
  10795. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10796. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10797. {
  10798. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10799. {
  10800. // Save profile to file
  10801. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10802. system(cmdBuf);
  10803. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10804. fp = fopen(cmdBuf, "w");
  10805. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10806. fclose(fp);
  10807. refreshStartTimer(&clientTime.RemoteStartWait);
  10808. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10809. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10810. }
  10811. else
  10812. {
  10813. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10814. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10815. }
  10816. }
  10817. else
  10818. {
  10819. refreshStartTimer(&clientTime.RemoteStartWait);
  10820. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10821. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10822. }
  10823. }
  10824. else
  10825. {
  10826. DEBUG_INFO("There is not any connector is idle.\n");
  10827. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10828. }
  10829. }
  10830. }
  10831. else
  10832. {
  10833. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10834. }
  10835. end:
  10836. json_object_put(RemoteStartTransaction);
  10837. sendRemoteStartConfirmation(uuid, comfirmstr);
  10838. return result;
  10839. }
  10840. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10841. {
  10842. mtrace();
  10843. int result = FAIL;
  10844. int match = FALSE;
  10845. int GunNO = 0;
  10846. int tempIndex = 0;
  10847. int transactionIdInt=0;
  10848. int transactionIdIsNULL= TRUE;
  10849. char comfirmstr[20];
  10850. json_object *RemoteStopTransaction;
  10851. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10852. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10853. if(server_pending == TRUE)
  10854. {
  10855. return 0;
  10856. }
  10857. RemoteStopTransaction = json_tokener_parse(payload);
  10858. if(!is_error(RemoteStopTransaction))
  10859. {
  10860. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10861. {
  10862. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10863. transactionIdIsNULL = FALSE;
  10864. }
  10865. }
  10866. json_object_put(RemoteStopTransaction);
  10867. if(transactionIdIsNULL == FALSE)
  10868. {
  10869. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10870. {
  10871. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10872. {
  10873. //check Transaction active
  10874. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10875. {
  10876. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10877. {
  10878. tempIndex = ((gun_index==2) ? 1: 0);
  10879. }
  10880. else
  10881. {
  10882. tempIndex = gun_index;
  10883. }
  10884. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10885. {
  10886. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10887. {
  10888. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10889. {
  10890. match = TRUE;
  10891. GunNO = gun_index;
  10892. }
  10893. }
  10894. }// END FOR CHAdeMO_QUANTITY
  10895. }
  10896. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10897. {
  10898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10899. {
  10900. tempIndex = ((gun_index==2) ? 1: 0);
  10901. }
  10902. else
  10903. {
  10904. tempIndex = gun_index;
  10905. }
  10906. for (int index = 0; index < CCS_QUANTITY; index++)
  10907. {
  10908. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10909. {
  10910. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10911. {
  10912. match = TRUE;
  10913. GunNO = gun_index;
  10914. }
  10915. }
  10916. }// END FOR CCS_QUANTITY
  10917. }
  10918. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10919. {
  10920. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10921. {
  10922. tempIndex = ((gun_index==2) ? 1: 0);
  10923. }
  10924. else
  10925. {
  10926. tempIndex = gun_index;
  10927. }
  10928. for (int index = 0; index < GB_QUANTITY; index++)
  10929. {
  10930. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10931. {
  10932. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10933. {
  10934. match = TRUE;
  10935. GunNO = gun_index;
  10936. }
  10937. }
  10938. }// END FOR GB_QUANTITY
  10939. }
  10940. else if(gunType[gun_index] == GUN_TYPE_DO)
  10941. {
  10942. tempIndex = gun_index;
  10943. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10944. {
  10945. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10946. {
  10947. 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
  10948. {
  10949. match = TRUE;
  10950. GunNO = gun_index;
  10951. }
  10952. }
  10953. }// END FOR GB_QUANTITY
  10954. }
  10955. else
  10956. {
  10957. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10958. {
  10959. tempIndex = 2;
  10960. }
  10961. else
  10962. {
  10963. tempIndex = gun_index;
  10964. }
  10965. for (int index = 0; index < AC_QUANTITY; index++)
  10966. {
  10967. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10968. {
  10969. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10970. {
  10971. match = TRUE;
  10972. GunNO = gun_index;
  10973. }
  10974. }
  10975. }// END FOR CHAdeMO_QUANTITY
  10976. } // END FOR AC ELSE
  10977. }// CHECK IF ResponseTransactionId == transactionIdInt
  10978. }//END FOR
  10979. if( match == TRUE)
  10980. {
  10981. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10982. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10983. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10984. }
  10985. else
  10986. {
  10987. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10988. }
  10989. }
  10990. else
  10991. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10992. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10993. return result;
  10994. }
  10995. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10996. {
  10997. mtrace();
  10998. int result = FAIL;
  10999. int connectorIdInt=0, reservationIdInt=0;
  11000. int tempIndex = 0;
  11001. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11002. char comfirmstr[20]={0};
  11003. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11004. int c = 0;
  11005. char *loc;
  11006. //char *ptr;
  11007. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11008. strcpy(sstrtemp, stringtrimspace(payload));
  11009. //***(1)connectorId ****/
  11010. c=0;
  11011. loc = strstr(sstrtemp, "connectorId");
  11012. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11013. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11014. {
  11015. sstr[c] = loc[strlen("connectorId")+2+c];
  11016. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11017. c++;
  11018. }
  11019. sstr[c] = '\0';
  11020. connectorIdInt = atoi(sstr);
  11021. //***(2)expiryDate ****/
  11022. loc = strstr(sstrtemp, "expiryDate");
  11023. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11024. c = 0;
  11025. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11026. {
  11027. sstr[c] = loc[3+strlen("expiryDate")+c];
  11028. c++;
  11029. }
  11030. sstr[c] = '\0';
  11031. strcpy(expiryDatestr, sstr);
  11032. //***(3)idTag ****/
  11033. loc = strstr(sstrtemp, "idTag");
  11034. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11035. c = 0;
  11036. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11037. {
  11038. sstr[c] = loc[3+strlen("idTag")+c];
  11039. c++;
  11040. }
  11041. sstr[c] = '\0';
  11042. strcpy(idTagstr, sstr);
  11043. //***(4)parentIdTag ****/
  11044. loc = strstr(sstrtemp, "parentIdTag");
  11045. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11046. c = 0;
  11047. if(loc == NULL)
  11048. {
  11049. strcpy(parentIdTagstr, "");
  11050. }
  11051. else
  11052. {
  11053. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11054. {
  11055. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11056. c++;
  11057. }
  11058. sstr[c] = '\0';
  11059. strcpy(parentIdTagstr, sstr);
  11060. }
  11061. //***(5)reservationId ****/
  11062. c=0;
  11063. loc = strstr(sstrtemp, "reservationId");
  11064. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11065. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11066. {
  11067. sstr[c] = loc[strlen("reservationId")+2+c];
  11068. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11069. c++;
  11070. }
  11071. sstr[c] = '\0';
  11072. reservationIdInt = atoi(sstr);
  11073. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11074. /*
  11075. enum SYSTEM_STATUS
  11076. {
  11077. SYS_MODE_BOOTING = 0,
  11078. SYS_MODE_IDLE = 1,
  11079. SYS_MODE_AUTHORIZING = 2,
  11080. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11081. SYS_MODE_REASSIGN = 4,
  11082. SYS_MODE_PREPARING = 5,
  11083. SYS_MODE_PREPARE_FOR_EV = 6,
  11084. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11085. SYS_MODE_CHARGING = 8,
  11086. SYS_MODE_TERMINATING = 9,
  11087. SYS_MODE_COMPLETE = 10,
  11088. SYS_MODE_ALARM = 11,
  11089. SYS_MODE_FAULT = 12,
  11090. SYS_MODE_RESERVATION = 13,
  11091. SYS_MODE_BOOKING = 14,
  11092. SYS_MODE_MAINTAIN = 15,
  11093. SYS_MODE_DEBUG = 16,
  11094. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11095. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11096. SYS_MODE_UPDATE = 19
  11097. };
  11098. */
  11099. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11100. {
  11101. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11102. goto end;
  11103. }
  11104. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11105. {
  11106. //check Transaction active
  11107. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11108. {
  11109. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11110. {
  11111. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11112. }
  11113. else
  11114. {
  11115. tempIndex = connectorIdInt -1;
  11116. }
  11117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11118. {
  11119. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11120. {
  11121. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11122. {
  11123. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11124. {
  11125. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11126. {
  11127. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11128. {
  11129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11130. }
  11131. else
  11132. {
  11133. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11135. }
  11136. }
  11137. 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'))
  11138. {
  11139. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11140. }
  11141. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11142. {
  11143. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11144. }
  11145. else
  11146. {
  11147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11148. }
  11149. }
  11150. 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
  11151. {
  11152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11153. }
  11154. }
  11155. else
  11156. {
  11157. //replace reservation
  11158. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11159. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11160. }
  11161. }
  11162. } // END FOR CHAdeMO_QUANTITY
  11163. }
  11164. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11165. {
  11166. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11167. {
  11168. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11169. }
  11170. else
  11171. {
  11172. tempIndex = connectorIdInt -1;
  11173. }
  11174. for (int index = 0; index < CCS_QUANTITY; index++)
  11175. {
  11176. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11177. {
  11178. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11179. {
  11180. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11181. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11182. {
  11183. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11184. {
  11185. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11186. {
  11187. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11188. }
  11189. else
  11190. {
  11191. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11192. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11193. }
  11194. }
  11195. 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'))
  11196. {
  11197. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11198. }
  11199. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11200. {
  11201. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11202. }
  11203. else
  11204. {
  11205. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11206. }
  11207. }
  11208. 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
  11209. {
  11210. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11211. }
  11212. }
  11213. else
  11214. {
  11215. //replace reservation
  11216. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11217. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11218. }
  11219. }
  11220. } // END FOR CCS_QUANTITY
  11221. }
  11222. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11223. {
  11224. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11225. {
  11226. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11227. }
  11228. else
  11229. {
  11230. tempIndex = connectorIdInt -1;
  11231. }
  11232. for (int index = 0; index < GB_QUANTITY; index++)
  11233. {
  11234. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11235. {
  11236. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11237. {
  11238. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11239. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11240. {
  11241. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11242. {
  11243. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11244. {
  11245. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11246. }
  11247. else
  11248. {
  11249. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11250. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11251. }
  11252. }
  11253. 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'))
  11254. {
  11255. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11256. }
  11257. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11258. {
  11259. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11260. }
  11261. else
  11262. {
  11263. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11264. }
  11265. }
  11266. 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
  11267. {
  11268. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11269. }
  11270. }
  11271. else
  11272. {
  11273. //replace reservation
  11274. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11276. }
  11277. }
  11278. }// END FOR GB_QUANTITY
  11279. }
  11280. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11281. {
  11282. tempIndex = connectorIdInt -1;
  11283. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11284. {
  11285. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11286. {
  11287. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11288. {
  11289. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11290. 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
  11291. {
  11292. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11293. {
  11294. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11295. {
  11296. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11297. }
  11298. else
  11299. {
  11300. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11301. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11302. }
  11303. }
  11304. 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'))
  11305. {
  11306. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11307. }
  11308. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11309. {
  11310. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11311. }
  11312. else
  11313. {
  11314. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11315. }
  11316. }
  11317. 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
  11318. {
  11319. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11320. }
  11321. }
  11322. else
  11323. {
  11324. //replace reservation
  11325. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11326. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11327. }
  11328. }
  11329. }// END FOR GB_QUANTITY
  11330. }
  11331. else
  11332. {
  11333. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11334. {
  11335. tempIndex = 2;
  11336. }
  11337. else
  11338. {
  11339. tempIndex = (connectorIdInt -1);
  11340. }
  11341. for (int index = 0; index < AC_QUANTITY; index++)
  11342. {
  11343. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11344. {
  11345. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11346. {
  11347. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11348. {
  11349. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11350. {
  11351. 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))
  11352. {
  11353. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11354. }
  11355. else
  11356. {
  11357. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11358. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11359. }
  11360. }
  11361. 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'))
  11362. {
  11363. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11364. }
  11365. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11366. {
  11367. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11368. }
  11369. else
  11370. {
  11371. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11372. }
  11373. }
  11374. 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
  11375. {
  11376. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11377. }
  11378. }
  11379. else
  11380. {
  11381. //replace reservation
  11382. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11383. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11384. }
  11385. }
  11386. } // END FOR AC_QUANTITY
  11387. }
  11388. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11389. }
  11390. else if(connectorIdInt == 0)
  11391. {
  11392. //check Transaction active
  11393. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11394. {
  11395. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11396. {
  11397. 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'))
  11398. {
  11399. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11400. goto end;
  11401. }
  11402. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11403. {
  11404. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11405. goto end;
  11406. }
  11407. 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
  11408. {
  11409. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11410. goto end;
  11411. }
  11412. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11413. {
  11414. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11415. goto end;
  11416. }
  11417. }
  11418. }// END FOR CHAdeMO_QUANTITY
  11419. for (int index = 0; index < CCS_QUANTITY; index++)
  11420. {
  11421. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11422. {
  11423. 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'))
  11424. {
  11425. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11426. goto end;
  11427. }
  11428. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11429. {
  11430. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11431. goto end;
  11432. }
  11433. 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
  11434. {
  11435. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11436. goto end;
  11437. }
  11438. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11439. {
  11440. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11441. goto end;
  11442. }
  11443. }
  11444. } // END FOR CCS_QUANTITY
  11445. for (int index = 0; index < GB_QUANTITY; index++)
  11446. {
  11447. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11448. {
  11449. 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'))
  11450. {
  11451. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11452. goto end;
  11453. }
  11454. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11455. {
  11456. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11457. goto end;
  11458. }
  11459. 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
  11460. {
  11461. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11462. goto end;
  11463. }
  11464. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11465. {
  11466. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11467. goto end;
  11468. }
  11469. }
  11470. } // END FOR GB_QUANTITY
  11471. for (int index = 0; index < AC_QUANTITY; index++)
  11472. {
  11473. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11474. {
  11475. 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'))
  11476. {
  11477. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11478. goto end;
  11479. }
  11480. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11481. {
  11482. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11483. goto end;
  11484. }
  11485. 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
  11486. {
  11487. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11488. goto end;
  11489. }
  11490. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11491. {
  11492. 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))
  11493. {
  11494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11495. goto end;
  11496. }
  11497. }
  11498. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11499. {
  11500. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11501. goto end;
  11502. }
  11503. }
  11504. }// END FOR AC_QUANTITY
  11505. //The connectorId is 0
  11506. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11507. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11508. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11509. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11510. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11511. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11512. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11513. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11514. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11515. result = TRUE;
  11516. return result;
  11517. }
  11518. else
  11519. {
  11520. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11521. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11522. }
  11523. if(strcmp(comfirmstr,"Accepted") == 0)
  11524. {
  11525. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11526. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11527. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11528. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11529. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11530. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11531. result = TRUE;
  11532. return result;
  11533. }
  11534. end:
  11535. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11536. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11537. return result;
  11538. }
  11539. int handleResetRequest(char *uuid, char *payload)
  11540. {
  11541. mtrace();
  11542. int result = FAIL;
  11543. char sstr[10]={0},sstrtemp[30]={ 0 };
  11544. char typestr[10]={0};
  11545. char comfirmstr[20]={0};
  11546. int c = 0;
  11547. char *loc;
  11548. DEBUG_INFO("handleResetRequest...\n");
  11549. strcpy(sstrtemp, stringtrimspace(payload));
  11550. loc = strstr(sstrtemp, "type");
  11551. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11552. c = 0;
  11553. while (loc[3+strlen("type")+c] != '\"')
  11554. {
  11555. sstr[c] = loc[3+strlen("type")+c];
  11556. c++;
  11557. }
  11558. sstr[c] = '\0';
  11559. strcpy(typestr,sstr);
  11560. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11561. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11562. {
  11563. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11564. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11565. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11566. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11567. }
  11568. else
  11569. {
  11570. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11571. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11572. result = PASS;
  11573. }
  11574. sendResetConfirmation(uuid, comfirmstr);
  11575. return result;
  11576. }
  11577. int handleSendLocalListRequest(char *uuid, char *payload)
  11578. {
  11579. mtrace();
  11580. int result = FAIL;
  11581. char comfirmstr[20];
  11582. int checkState_Faulted = FALSE;
  11583. json_object *SendLocalList;
  11584. DEBUG_INFO("handleSendLocalListRequest...\n");
  11585. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11586. {
  11587. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11588. goto end;
  11589. }
  11590. //check Charge Point state
  11591. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11592. {
  11593. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11594. {
  11595. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11596. }
  11597. }
  11598. for (int index = 0; index < CCS_QUANTITY; index++)
  11599. {
  11600. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11601. {
  11602. checkState_Faulted = TRUE; //OCPP Status
  11603. }
  11604. }
  11605. for (int index = 0; index < GB_QUANTITY; index++)
  11606. {
  11607. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11608. {
  11609. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11610. }
  11611. }
  11612. //check Charge Point state
  11613. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11614. {
  11615. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11616. {
  11617. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11618. }
  11619. }
  11620. //check Charge Point state
  11621. for (int index = 0; index < AC_QUANTITY; index++)
  11622. {
  11623. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11624. {
  11625. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11626. }
  11627. }
  11628. if(checkState_Faulted == TRUE)
  11629. {
  11630. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11631. goto end;
  11632. }
  11633. // Parsing payload
  11634. SendLocalList = json_tokener_parse(payload);
  11635. if(!is_error(SendLocalList))
  11636. {
  11637. // Required data
  11638. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11639. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11640. // Optional data
  11641. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11642. {
  11643. //Check UpdateType
  11644. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11645. {
  11646. //Local list full update
  11647. DEBUG_INFO("Local list full update.\n");
  11648. locallistVersion = 0;
  11649. OCPP_getListVerion();
  11650. /*if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11651. {
  11652. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11653. goto end;
  11654. }*/
  11655. OCPP_cleanLocalList();
  11656. }
  11657. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11658. {
  11659. //Local list different update
  11660. DEBUG_INFO("Local list different update.\n");
  11661. locallistVersion = 0;
  11662. OCPP_getListVerion();
  11663. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11664. {
  11665. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11666. goto end;
  11667. }
  11668. }
  11669. else
  11670. {
  11671. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11672. goto end;
  11673. }
  11674. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  11675. {
  11676. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  11677. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11678. goto end;
  11679. }
  11680. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11681. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11682. {
  11683. 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")));
  11684. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11685. {
  11686. 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")));
  11687. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11688. 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")));
  11689. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11690. 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")));
  11691. }
  11692. // Add to db
  11693. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11694. {
  11695. //Local list full update
  11696. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11697. idx,
  11698. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11699. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11700. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11701. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11702. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11703. // update list
  11704. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11705. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11706. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11707. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11708. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11709. }
  11710. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11711. {
  11712. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11713. idx,
  11714. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11715. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11716. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11717. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11718. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  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. }
  11726. }
  11727. else
  11728. {
  11729. //Check UpdateType
  11730. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11731. {
  11732. //Local list full update
  11733. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11734. OCPP_cleanLocalList();
  11735. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11736. goto end;
  11737. }
  11738. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11739. {
  11740. //Local list different update
  11741. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11742. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11743. goto end;
  11744. }
  11745. }
  11746. result = PASS;
  11747. }
  11748. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11749. end:
  11750. json_object_put(SendLocalList);
  11751. sendSendLocalListConfirmation(uuid, comfirmstr);
  11752. return result;
  11753. }
  11754. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11755. {
  11756. mtrace();
  11757. int result = FAIL;
  11758. struct StructSetChargingProfile SetProfileReq = {0};
  11759. int tempchargingProfileIdInt;
  11760. int tempstackLevelInt;
  11761. int chargingSchedulePeriodCount = 0;
  11762. char comfirmstr[20]={0};
  11763. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11764. char rmFileCmd[128]={0};
  11765. int profileQuantity = 0;
  11766. int replaceableProfileCnt = 0;
  11767. json_object *SetChargingProfile;
  11768. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11769. SetChargingProfile = json_tokener_parse(payload);
  11770. if(!is_error(SetChargingProfile))
  11771. {
  11772. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11773. {
  11774. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11775. }
  11776. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11777. {
  11778. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11779. {
  11780. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11781. }
  11782. else
  11783. {
  11784. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11785. DEBUG_WARN("Cannot find chargingProfileId field.");
  11786. goto end;
  11787. }
  11788. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11789. {
  11790. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11791. }
  11792. else
  11793. {
  11794. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11795. DEBUG_WARN("Cannot find stackLevel field.");
  11796. goto end;
  11797. }
  11798. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11799. {
  11800. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11801. }
  11802. else
  11803. {
  11804. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11805. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  11806. goto end;
  11807. }
  11808. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11809. {
  11810. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11811. }
  11812. else
  11813. {
  11814. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11815. DEBUG_WARN("Cannot find chargingProfileKind field.");
  11816. goto end;
  11817. }
  11818. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11819. {
  11820. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11821. }
  11822. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11823. {
  11824. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11825. }
  11826. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11827. {
  11828. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11829. }
  11830. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11831. {
  11832. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11833. }
  11834. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11835. {
  11836. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11837. {
  11838. 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")));
  11839. }
  11840. else
  11841. {
  11842. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11843. DEBUG_WARN("Cannot find chargingRateUnit field.");
  11844. goto end;
  11845. }
  11846. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11847. {
  11848. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11849. }
  11850. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11851. {
  11852. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11853. }
  11854. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11855. {
  11856. 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")));
  11857. }
  11858. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11859. {
  11860. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11861. if(chargingSchedulePeriodCount <= 10)
  11862. {
  11863. 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++)
  11864. {
  11865. 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)
  11866. {
  11867. 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"));
  11868. }
  11869. else
  11870. {
  11871. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11872. DEBUG_WARN("Cannot find startPeriod field.");
  11873. goto end;
  11874. }
  11875. 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)
  11876. {
  11877. 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"));
  11878. }
  11879. else
  11880. {
  11881. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11882. DEBUG_WARN("Cannot find limit field.");
  11883. goto end;
  11884. }
  11885. 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)
  11886. {
  11887. 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"));
  11888. }
  11889. }
  11890. }
  11891. }
  11892. else
  11893. {
  11894. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11895. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  11896. goto end;
  11897. }
  11898. }
  11899. else
  11900. {
  11901. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11902. DEBUG_WARN("Cannot find chargingSchedule field.");
  11903. goto end;
  11904. }
  11905. }
  11906. }
  11907. // Profile periods quantity check
  11908. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11909. {
  11910. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11911. goto end;
  11912. }
  11913. // Check invalid limit
  11914. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  11915. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  11916. {
  11917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11918. {
  11919. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11920. {
  11921. 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)))) ||
  11922. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11923. {
  11924. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11925. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11926. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11927. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11928. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11929. goto end;
  11930. }
  11931. }
  11932. }
  11933. else
  11934. {
  11935. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11936. {
  11937. 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) ||
  11938. (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)))
  11939. {
  11940. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11941. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11942. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11943. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11944. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11945. goto end;
  11946. }
  11947. }
  11948. }
  11949. }
  11950. // Profile purpose info check
  11951. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11952. {
  11953. FILE *fp;
  11954. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11955. if(SetProfileReq.ConnectorId != 0)
  11956. {
  11957. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11958. goto end;
  11959. }
  11960. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11961. if (!fp)
  11962. {
  11963. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11964. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11965. }
  11966. else
  11967. {
  11968. char *line = NULL;
  11969. size_t len = 0;
  11970. while(getline(&line, &len, fp) != -1)
  11971. {
  11972. json_object *obj = NULL;
  11973. obj = json_tokener_parse(line);
  11974. if(is_error(obj))
  11975. {
  11976. DEBUG_ERROR("Parse txProfile from file error.\n");
  11977. }
  11978. else
  11979. {
  11980. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11981. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11982. {
  11983. profileQuantity += 1;
  11984. }
  11985. else
  11986. replaceableProfileCnt += 1;
  11987. }
  11988. }
  11989. }
  11990. fclose(fp);
  11991. }
  11992. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11993. {
  11994. FILE *fp;
  11995. char filename[128]={0};
  11996. int tmpProfileQuantity;
  11997. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11998. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11999. {
  12000. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12001. goto end;
  12002. }
  12003. if(SetProfileReq.ConnectorId == 0)
  12004. {
  12005. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12006. {
  12007. tmpProfileQuantity = 0;
  12008. memset(filename, 0, ARRAY_SIZE(filename));
  12009. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12010. fp = fopen(filename, "r");
  12011. if (!fp)
  12012. {
  12013. DEBUG_INFO("%s does not create.\n", filename);
  12014. fp = fopen(filename, "w+");
  12015. }
  12016. else
  12017. {
  12018. char *line = NULL;
  12019. size_t len = 0;
  12020. while(getline(&line, &len, fp) != -1)
  12021. {
  12022. json_object *obj = NULL;
  12023. obj = json_tokener_parse(line);
  12024. if(is_error(obj))
  12025. {
  12026. DEBUG_ERROR("Parse txProfile from file error.\n");
  12027. }
  12028. else
  12029. {
  12030. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12031. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12032. {
  12033. tmpProfileQuantity += 1;
  12034. }
  12035. else
  12036. replaceableProfileCnt += 1;
  12037. }
  12038. }
  12039. }
  12040. fclose(fp);
  12041. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12042. }
  12043. }
  12044. else
  12045. {
  12046. memset(filename, 0, ARRAY_SIZE(filename));
  12047. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12048. fp = fopen(filename, "r");
  12049. if (!fp)
  12050. {
  12051. DEBUG_INFO("%s does not create.\n", filename);
  12052. fp = fopen(filename, "w+");
  12053. }
  12054. else
  12055. {
  12056. char *line = NULL;
  12057. size_t len = 0;
  12058. while(getline(&line, &len, fp) != -1)
  12059. {
  12060. json_object *obj = NULL;
  12061. obj = json_tokener_parse(line);
  12062. if(is_error(obj))
  12063. {
  12064. DEBUG_ERROR("Parse txProfile from file error.\n");
  12065. }
  12066. else
  12067. {
  12068. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12069. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12070. {
  12071. profileQuantity += 1;
  12072. }
  12073. else
  12074. replaceableProfileCnt += 1;
  12075. }
  12076. }
  12077. }
  12078. fclose(fp);
  12079. }
  12080. }
  12081. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12082. {
  12083. int isMatchTransactiodId= FALSE;
  12084. FILE *fp;
  12085. char filename[128]={0};
  12086. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12087. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12088. if(SetProfileReq.ConnectorId == 0)
  12089. {
  12090. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12091. goto end;
  12092. }
  12093. int tempIndex = 0;
  12094. //check Transaction active
  12095. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12096. {
  12097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12098. {
  12099. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12100. }
  12101. else
  12102. {
  12103. tempIndex = SetProfileReq.ConnectorId -1;
  12104. }
  12105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12106. {
  12107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12108. {
  12109. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12110. {
  12111. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12112. {
  12113. isMatchTransactiodId = TRUE;
  12114. break;
  12115. }
  12116. }
  12117. }
  12118. }
  12119. }
  12120. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12121. {
  12122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12123. {
  12124. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12125. }
  12126. else
  12127. {
  12128. tempIndex = SetProfileReq.ConnectorId -1;
  12129. }
  12130. for (int index = 0; index < CCS_QUANTITY; index++)
  12131. {
  12132. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12133. {
  12134. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12135. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12136. {
  12137. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12138. {
  12139. isMatchTransactiodId = TRUE;
  12140. break;
  12141. }
  12142. }
  12143. }
  12144. }
  12145. }
  12146. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12147. {
  12148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12149. {
  12150. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12151. }
  12152. else
  12153. {
  12154. tempIndex = SetProfileReq.ConnectorId -1;
  12155. }
  12156. for (int index = 0; index < GB_QUANTITY; index++)
  12157. {
  12158. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12159. {
  12160. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12161. {
  12162. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12163. {
  12164. isMatchTransactiodId = TRUE;
  12165. break;
  12166. }
  12167. }
  12168. }
  12169. }
  12170. }
  12171. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12172. {
  12173. tempIndex = SetProfileReq.ConnectorId -1;
  12174. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12175. {
  12176. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12177. {
  12178. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12179. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12180. {
  12181. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12182. {
  12183. isMatchTransactiodId = TRUE;
  12184. break;
  12185. }
  12186. }
  12187. }
  12188. }
  12189. }
  12190. else
  12191. {
  12192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12193. {
  12194. tempIndex = 2;
  12195. }
  12196. else
  12197. {
  12198. tempIndex = (SetProfileReq.ConnectorId -1);
  12199. }
  12200. for (int index = 0; index < AC_QUANTITY; index++)
  12201. {
  12202. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12203. {
  12204. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12205. {
  12206. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12207. {
  12208. isMatchTransactiodId = TRUE;
  12209. break;
  12210. }
  12211. }
  12212. }
  12213. }
  12214. }
  12215. //check Transaction active
  12216. if(isMatchTransactiodId == FALSE)
  12217. {
  12218. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12219. goto end;
  12220. }
  12221. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12222. {
  12223. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12224. goto end;
  12225. }
  12226. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12227. fp = fopen(filename, "r");
  12228. if (!fp)
  12229. {
  12230. DEBUG_INFO("%s does not create.\n", filename);
  12231. fp = fopen(filename, "w+");
  12232. }
  12233. else
  12234. {
  12235. char *line = NULL;
  12236. size_t len = 0;
  12237. while(getline(&line, &len, fp) != -1)
  12238. {
  12239. json_object *obj = NULL;
  12240. obj = json_tokener_parse(line);
  12241. if(is_error(obj))
  12242. {
  12243. DEBUG_ERROR("Parse txProfile from file error.\n");
  12244. }
  12245. else
  12246. {
  12247. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12248. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12249. {
  12250. profileQuantity += 1;
  12251. }
  12252. else
  12253. replaceableProfileCnt += 1;
  12254. }
  12255. }
  12256. }
  12257. fclose(fp);
  12258. }
  12259. // Check ChargeProfileMaxStackLevel
  12260. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12261. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12262. {
  12263. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12264. goto end;
  12265. }
  12266. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12267. {
  12268. FILE *fp;
  12269. char dataLine[4096]={0};
  12270. char fnametemp[128]={0};
  12271. int tmpProfileQuantity;
  12272. //Check ChargePointMaxProfile.json exit
  12273. profileQuantity = 0;
  12274. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12275. {
  12276. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12277. //Check Charging Profile Count
  12278. tmpProfileQuantity = 0;
  12279. while(fscanf(fp, "%s", dataLine) != EOF)
  12280. {
  12281. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12282. {
  12283. profileQuantity += 1;
  12284. tmpProfileQuantity += 1;
  12285. }
  12286. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12287. }
  12288. fclose(fp);
  12289. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12290. }
  12291. //Check TxDefaultProfile_%d.json
  12292. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12293. {
  12294. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12295. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12296. if((access(fnametemp,F_OK))!=-1)
  12297. {
  12298. fp = fopen(fnametemp, "r");
  12299. //Check Charging Profile Count
  12300. tmpProfileQuantity = 0;
  12301. while(fscanf(fp, "%s", dataLine) != EOF)
  12302. {
  12303. //DEBUG_INFO("word=%s\n",word);
  12304. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12305. {
  12306. profileQuantity += 1;
  12307. tmpProfileQuantity += 1;
  12308. }
  12309. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12310. }
  12311. fclose(fp);
  12312. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12313. }
  12314. }
  12315. //Check TxProfile_%d.json
  12316. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12317. {
  12318. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12319. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12320. if((access(fnametemp,F_OK))!=-1)
  12321. {
  12322. fp = fopen(fnametemp, "r");
  12323. //Check Charging Profile Count
  12324. tmpProfileQuantity = 0;
  12325. while(fscanf(fp, "%s", dataLine) != EOF)
  12326. {
  12327. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12328. {
  12329. profileQuantity += 1;
  12330. tmpProfileQuantity += 1;
  12331. }
  12332. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12333. }
  12334. fclose(fp);
  12335. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12336. }
  12337. }
  12338. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12339. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12340. // To check total Profile quantity
  12341. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12342. {
  12343. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12344. {
  12345. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12346. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12347. goto end;
  12348. }
  12349. }
  12350. else
  12351. {
  12352. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12353. {
  12354. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12355. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12356. goto end;
  12357. }
  12358. }
  12359. }
  12360. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12361. //**********************************Write to File********************************************************/
  12362. {
  12363. FILE *infile;
  12364. FILE *outfile;
  12365. char dataLine[4096]={0};
  12366. char filename[128]={0};
  12367. int chkChar=0;
  12368. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12369. {
  12370. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12371. {
  12372. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12373. }
  12374. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12375. {
  12376. if(SetProfileReq.ConnectorId==0)
  12377. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12378. else
  12379. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12380. }
  12381. else
  12382. {
  12383. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12384. }
  12385. infile = fopen (filename, "r");
  12386. outfile = fopen (tempfile, "w");
  12387. chkChar = fgetc(infile);
  12388. rewind(infile);
  12389. if(chkChar == EOF)
  12390. {
  12391. // Profile is empty
  12392. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12393. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12394. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12395. fclose(infile);
  12396. fclose(outfile);
  12397. sprintf(rmFileCmd,"rm -f %s",filename);
  12398. system(rmFileCmd);
  12399. rename(tempfile, filename);
  12400. }
  12401. else
  12402. {
  12403. // Profile is not empty
  12404. int ChargingProfileAdded = FALSE;
  12405. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12406. {
  12407. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12408. json_object *tmpChargingProfile;
  12409. tmpChargingProfile = json_tokener_parse(dataLine);
  12410. if(!is_error(SetChargingProfile))
  12411. {
  12412. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12413. {
  12414. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12415. {
  12416. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12417. }
  12418. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12419. {
  12420. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12421. }
  12422. }
  12423. }
  12424. json_object_put(tmpChargingProfile);
  12425. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12426. {
  12427. if(ChargingProfileAdded == FALSE)
  12428. {
  12429. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12430. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12431. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12432. ChargingProfileAdded = TRUE;
  12433. }
  12434. }
  12435. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12436. {
  12437. if(ChargingProfileAdded == FALSE)
  12438. {
  12439. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12440. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12441. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12442. ChargingProfileAdded = TRUE;
  12443. }
  12444. }
  12445. else
  12446. {
  12447. fprintf(outfile,"%s\n",dataLine);
  12448. if(ChargingProfileAdded == FALSE)
  12449. {
  12450. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12451. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12452. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12453. ChargingProfileAdded = TRUE;
  12454. }
  12455. }
  12456. } // end of while loop
  12457. fclose(infile);
  12458. fclose(outfile);
  12459. sprintf(rmFileCmd,"rm -f %s",filename);
  12460. system(rmFileCmd);
  12461. rename(tempfile, filename);
  12462. }
  12463. }
  12464. sleep(1);
  12465. result = TRUE;
  12466. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12467. }
  12468. end:
  12469. json_object_put(SetChargingProfile);
  12470. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12471. {
  12472. if(SetProfileReq.ConnectorId == 0)
  12473. {
  12474. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12475. {
  12476. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12477. }
  12478. }
  12479. else
  12480. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12481. }
  12482. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12483. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12484. return result;
  12485. }
  12486. int handleTriggerMessageRequest(char *uuid, char *payload)
  12487. {
  12488. mtrace();
  12489. int result = FAIL;
  12490. int connectorIdIsNULL = FALSE;
  12491. int connectorIdInt =0;
  12492. char sstr[40]={0},sstrtemp[100]={ 0 };
  12493. char requestedMessagestr[40]={0};
  12494. char comfirmstr[20]={0};
  12495. int c = 0;
  12496. char *loc;
  12497. DEBUG_INFO("handleTriggerMessageRequest\n");
  12498. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12499. strcpy(sstrtemp, stringtrimspace(payload));
  12500. c = 0;
  12501. loc = strstr(sstrtemp, "requestedMessage");
  12502. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12503. {
  12504. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12505. c++;
  12506. }
  12507. sstr[c] = '\0';
  12508. strcpy(requestedMessagestr, sstr);
  12509. c = 0;
  12510. loc = strstr(sstrtemp, "connectorId");
  12511. if(loc == NULL)
  12512. {
  12513. connectorIdIsNULL = TRUE;
  12514. }
  12515. else
  12516. {
  12517. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12518. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12519. {
  12520. sstr[c] = loc[strlen("connectorId")+2+c];
  12521. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12522. c++;
  12523. }
  12524. sstr[c] = '\0';
  12525. connectorIdInt = atoi(sstr);
  12526. }
  12527. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12528. {
  12529. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12530. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12531. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12532. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12533. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12534. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12535. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12536. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12537. {
  12538. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12539. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12540. return TRUE;
  12541. }
  12542. else
  12543. {
  12544. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12545. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12546. }
  12547. }
  12548. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12549. {
  12550. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12551. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12552. return TRUE;
  12553. }
  12554. //==========================
  12555. // Trigger message
  12556. //==========================
  12557. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12558. {
  12559. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12560. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12561. {
  12562. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12563. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12564. }
  12565. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12566. }
  12567. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12568. {
  12569. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12570. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12571. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12572. }
  12573. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12574. {
  12575. //sendBootNotificationRequest();
  12576. server_sign = FALSE;
  12577. }
  12578. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12579. {
  12580. refreshStartTimer(&clientTime.Heartbeat);
  12581. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12582. }
  12583. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12584. {
  12585. if(connectorIdIsNULL == FALSE)
  12586. {
  12587. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12588. {
  12589. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12590. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12591. }
  12592. }
  12593. else
  12594. {
  12595. for(int idx=0;idx< gunTotalNumber;idx++)
  12596. {
  12597. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12598. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12599. }
  12600. }
  12601. }
  12602. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12603. {
  12604. if(connectorIdIsNULL == FALSE)
  12605. {
  12606. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12607. {
  12608. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12609. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12610. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12611. }
  12612. }
  12613. else
  12614. {
  12615. for(int idx=0;idx< gunTotalNumber;idx++)
  12616. {
  12617. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12618. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12619. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12620. }
  12621. }
  12622. }
  12623. return result;
  12624. }
  12625. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12626. {
  12627. mtrace();
  12628. int result = FAIL;
  12629. int connectorIdInt =0;
  12630. char comfirmstr[20]={0};
  12631. int tempIndex = 0;
  12632. json_object *UnlockConnector;
  12633. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12634. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12635. UnlockConnector = json_tokener_parse(payload);
  12636. if(!is_error(UnlockConnector))
  12637. {
  12638. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12639. {
  12640. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12641. }
  12642. }
  12643. json_object_put(UnlockConnector);
  12644. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12645. if(gunTotalNumber == 0)
  12646. {
  12647. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12648. goto end;
  12649. }
  12650. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12651. {
  12652. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12653. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12654. goto end;
  12655. }
  12656. else
  12657. {
  12658. //check Transaction active
  12659. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12660. {
  12661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12662. {
  12663. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12664. }
  12665. else
  12666. {
  12667. tempIndex = connectorIdInt -1;
  12668. }
  12669. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12670. {
  12671. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12672. {
  12673. //stop Transaction
  12674. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12675. }
  12676. }
  12677. }
  12678. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12679. {
  12680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12681. {
  12682. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12683. }
  12684. else
  12685. {
  12686. tempIndex = connectorIdInt -1;
  12687. }
  12688. for (int index = 0; index < CCS_QUANTITY; index++)
  12689. {
  12690. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12691. {
  12692. //stop Transaction
  12693. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12694. }
  12695. }
  12696. }
  12697. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12698. {
  12699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12700. {
  12701. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12702. }
  12703. else
  12704. {
  12705. tempIndex = connectorIdInt -1;
  12706. }
  12707. for (int index = 0; index < GB_QUANTITY; index++)
  12708. {
  12709. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12710. {
  12711. //stop Transaction
  12712. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12713. }
  12714. }
  12715. }
  12716. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12717. {
  12718. tempIndex = connectorIdInt -1;
  12719. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12720. {
  12721. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12722. {
  12723. //stop Transaction
  12724. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12725. }
  12726. }
  12727. }
  12728. else
  12729. {
  12730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12731. {
  12732. tempIndex = 2;
  12733. }
  12734. else
  12735. {
  12736. tempIndex = connectorIdInt-1;
  12737. }
  12738. for (int index = 0; index < AC_QUANTITY; index++)
  12739. {
  12740. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12741. {
  12742. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12743. }
  12744. }
  12745. }
  12746. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12747. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12748. result = TRUE;
  12749. return result;
  12750. }
  12751. end:
  12752. //json_object_put(obj); --- remove temporally
  12753. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12754. return result;
  12755. }
  12756. static char UpdateFirmwarepayloadData[300]={0};
  12757. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12758. {
  12759. mtrace();
  12760. int result = FAIL;
  12761. pthread_t t;
  12762. sendUpdateFirmwareConfirmation(uuid);
  12763. memset(UpdateFirmwarepayloadData, 0, 300);
  12764. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12765. if(!interLock.isUpdateFirmwareGoing)
  12766. {
  12767. interLock.isUpdateFirmwareGoing = 1;
  12768. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12769. sleep(1);
  12770. }
  12771. else
  12772. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12773. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12774. return result;
  12775. }
  12776. void *UpdateFirmwareProcess(void *data)
  12777. {
  12778. pthread_detach(pthread_self());
  12779. mtrace();
  12780. int retriesInt =0, retryIntervalInt=0;
  12781. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12782. int port=0;
  12783. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12784. int isSuccess = 0;
  12785. char ftpbuf[512];
  12786. char temp[100];
  12787. char * pch;
  12788. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12789. json_object *UpdateFirmware;
  12790. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12791. if(!is_error(UpdateFirmware))
  12792. {
  12793. // Required data
  12794. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12795. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12796. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12797. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12798. // Optional data
  12799. if(json_object_object_get(UpdateFirmware, "retries"))
  12800. {
  12801. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12802. }
  12803. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12804. {
  12805. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12806. }
  12807. }
  12808. json_object_put(UpdateFirmware);
  12809. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12810. memset(path, 0, ARRAY_SIZE(path));
  12811. // Wait retrieveData
  12812. if(strlen(retrieveDatestr) > 10)
  12813. {
  12814. do
  12815. {
  12816. sleep(1);
  12817. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12818. }
  12819. // Ready to download
  12820. system("rm -f /mnt/*");
  12821. if(strncmp(locationstr,"http", 4) == 0)
  12822. {
  12823. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12824. sprintf(ftppath,"/%s", path);
  12825. DEBUG_INFO("locationstr: %s\n", locationstr);
  12826. DEBUG_INFO("protocol: %s\n",protocol);
  12827. DEBUG_INFO("host: %s\n",host);
  12828. DEBUG_INFO("path: %s\n",path);
  12829. DEBUG_INFO("ftppath: %s\n",ftppath);
  12830. int ftppathlen=strlen(ftppath);
  12831. int i=1;
  12832. char filenametemp[50];
  12833. while(i < ftppathlen)
  12834. {
  12835. int len=ftppathlen-i;
  12836. if(ftppath[len]== 47) // '/' ascll code: 47
  12837. {
  12838. DEBUG_INFO("compare '/' all right\n");
  12839. break;
  12840. }
  12841. i=i+1;
  12842. }
  12843. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12844. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12845. filenametemp[i+1] = 0;
  12846. do
  12847. {
  12848. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12849. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12850. sleep(1);
  12851. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12852. if(!isSuccess)
  12853. {
  12854. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12855. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12856. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12857. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12858. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12859. }
  12860. else
  12861. {
  12862. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12863. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12864. }
  12865. retriesInt--;
  12866. }while((isSuccess == 0)&&(retriesInt >= 0));
  12867. }
  12868. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  12869. {
  12870. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12871. memset(temp, 0, ARRAY_SIZE(temp));
  12872. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12873. strcpy(ftpbuf, locationstr);
  12874. int ftppathlen=strlen(ftpbuf);
  12875. int i=1;
  12876. char filenametemp[50];
  12877. while(i < ftppathlen)
  12878. {
  12879. int len=ftppathlen-i;
  12880. if(ftpbuf[len]== 47) // '/' ascii code: 47
  12881. {
  12882. DEBUG_INFO(" compare '/' all right\n");
  12883. break;
  12884. }
  12885. i=i+1;
  12886. }
  12887. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12888. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12889. filenametemp[i+1] = 0;
  12890. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12891. pch=strchr(temp,'@');
  12892. if(pch==NULL)
  12893. {
  12894. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12895. protocol, host, &port, path);
  12896. strcpy(user,"anonymous");
  12897. strcpy(password,"");
  12898. }
  12899. else
  12900. {
  12901. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  12902. protocol, user, host, &port, path);
  12903. }
  12904. sscanf(host,"%[^/]%s",host1, path1);
  12905. sprintf(ftppath,"%s:/%s", host,path);
  12906. if(port == 0)
  12907. {
  12908. port = 21;
  12909. }
  12910. do
  12911. {
  12912. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12913. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12914. sleep(1);
  12915. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  12916. if(!isSuccess)
  12917. {
  12918. //BulldogUtil.sleepMs(interval*1000);
  12919. DEBUG_INFO("Update firmware request and download file fail.\n");
  12920. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12921. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12922. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12923. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12924. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12925. }
  12926. else
  12927. {
  12928. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12929. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12930. }
  12931. retriesInt--;
  12932. }while((!isSuccess)&&(retriesInt >= 0));
  12933. }
  12934. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12935. {
  12936. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12937. memset(temp, 0, ARRAY_SIZE(temp));
  12938. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12939. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12940. int ftppathlen=strlen(ftpbuf);
  12941. int i=1;
  12942. char filenametemp[50];
  12943. while(i < ftppathlen)
  12944. {
  12945. int len=ftppathlen-i;
  12946. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12947. {
  12948. DEBUG_INFO(" compare '/' all right\n");
  12949. break;
  12950. }
  12951. i=i+1;
  12952. }
  12953. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12954. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12955. filenametemp[i+1] = 0;
  12956. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12957. pch=strchr(temp,'@');
  12958. if(pch==NULL)
  12959. {
  12960. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12961. protocol, host, &port, path);
  12962. strcpy(user,"anonymous");
  12963. strcpy(password,"");
  12964. }
  12965. else
  12966. {
  12967. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12968. protocol, user, password, host, &port, path);
  12969. }
  12970. sscanf(host,"%[^/]%s",host1, path1);
  12971. sprintf(ftppath,"%s", path1);
  12972. //DEBUG_INFO("protocol =%s\n",protocol);
  12973. //DEBUG_INFO("user =%s\n",user);
  12974. //DEBUG_INFO("password =%s\n",password);
  12975. //DEBUG_INFO("host1 =%s\n",host1);
  12976. //DEBUG_INFO("port =%d\n",port);
  12977. //DEBUG_INFO("path1 =%s\n",path1);
  12978. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12979. //ftpFile(host, user, password, port, ftppath, fname);
  12980. //download firmware pthred
  12981. if(port == 0)
  12982. {
  12983. port = 21;
  12984. }
  12985. do
  12986. {
  12987. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12988. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12989. sleep(1);
  12990. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12991. if(!isSuccess)
  12992. {
  12993. //BulldogUtil.sleepMs(interval*1000);
  12994. DEBUG_INFO("Update firmware request and download file fail.\n");
  12995. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12996. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12997. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12998. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12999. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13000. }
  13001. else
  13002. {
  13003. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13004. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13005. }
  13006. retriesInt--;
  13007. }while((!isSuccess)&&(retriesInt >= 0));
  13008. }
  13009. else
  13010. {
  13011. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13012. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13013. sleep(1);
  13014. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13015. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13016. }
  13017. // OCPPPH only, must announce CSU upgrade firmware
  13018. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13019. interLock.isUpdateFirmwareGoing = 0;
  13020. pthread_exit(NULL);
  13021. }
  13022. int handleCertificateSignedRequest(char *uuid, char *payload)
  13023. {
  13024. mtrace();
  13025. int result = PASS;
  13026. json_object *CertificateSigned;
  13027. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13028. CertificateSigned = json_tokener_parse(payload);
  13029. if(!is_error(CertificateSigned))
  13030. {
  13031. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13032. }
  13033. json_object_put(CertificateSigned);
  13034. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  13035. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  13036. fclose(fp);
  13037. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13038. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  13039. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  13040. sendCertificateSignedConfirmation(uuid);
  13041. return result;
  13042. }
  13043. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13044. {
  13045. mtrace();
  13046. int result = PASS;
  13047. json_object *DeleteCertificate;
  13048. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13049. DeleteCertificate = json_tokener_parse(payload);
  13050. if(!is_error(DeleteCertificate))
  13051. {
  13052. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13053. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13054. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13055. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13056. }
  13057. json_object_put(DeleteCertificate);
  13058. /*
  13059. * TODO: Delete certificateSigned process
  13060. */
  13061. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  13062. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  13063. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  13064. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  13065. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  13066. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  13067. sendDeleteCertificateConfirmation(uuid);
  13068. return result;
  13069. }
  13070. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13071. {
  13072. mtrace();
  13073. int result = PASS;
  13074. json_object *ExtendedTriggerMessage;
  13075. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13076. ExtendedTriggerMessage = json_tokener_parse(payload);
  13077. if(!is_error(ExtendedTriggerMessage))
  13078. {
  13079. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13080. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13081. {
  13082. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13083. }
  13084. else
  13085. {
  13086. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13087. }
  13088. }
  13089. json_object_put(ExtendedTriggerMessage);
  13090. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13091. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13092. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13093. {
  13094. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13095. }
  13096. else
  13097. {
  13098. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13099. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13100. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13101. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13102. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13103. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13104. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13105. {
  13106. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13107. }
  13108. else
  13109. {
  13110. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13111. }
  13112. }
  13113. sendExtendedTriggerMessageConfirmation(uuid);
  13114. //==========================
  13115. // Trigger message
  13116. //==========================
  13117. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13118. {
  13119. //sendBootNotificationRequest();
  13120. server_sign = FALSE;
  13121. }
  13122. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13123. {
  13124. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13125. }
  13126. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13127. {
  13128. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13129. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13130. {
  13131. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13132. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13133. }
  13134. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13135. }
  13136. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13137. {
  13138. refreshStartTimer(&clientTime.Heartbeat);
  13139. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13140. }
  13141. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13142. {
  13143. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13144. {
  13145. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13146. }
  13147. else
  13148. {
  13149. for(int idx=0;idx< gunTotalNumber;idx++)
  13150. {
  13151. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13152. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13153. }
  13154. }
  13155. }
  13156. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13157. {
  13158. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13159. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13160. {
  13161. 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\" &");
  13162. }
  13163. }
  13164. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13165. {
  13166. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13167. {
  13168. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13169. }
  13170. else
  13171. {
  13172. for(int idx=0;idx< gunTotalNumber;idx++)
  13173. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13174. }
  13175. }
  13176. return result;
  13177. }
  13178. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13179. {
  13180. mtrace();
  13181. int result = PASS;
  13182. json_object *GetInstalledCertificateIds;
  13183. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13184. GetInstalledCertificateIds = json_tokener_parse(payload);
  13185. if(!is_error(GetInstalledCertificateIds))
  13186. {
  13187. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13188. }
  13189. json_object_put(GetInstalledCertificateIds);
  13190. /*
  13191. * TODO: Return installed certificate process
  13192. */
  13193. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13194. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13195. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13196. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13197. sendGetInstalledCertificateIdsConfirmation(uuid);
  13198. return result;
  13199. }
  13200. int handleGetLogRequest(char *uuid, char *payload)
  13201. {
  13202. mtrace();
  13203. int result = PASS;
  13204. json_object *GetLog;
  13205. DEBUG_INFO("handleGetLogRequest...\n");
  13206. GetLog = json_tokener_parse(payload);
  13207. if(!is_error(GetLog))
  13208. {
  13209. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13210. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13211. if(json_object_object_get(GetLog, "retries") != NULL)
  13212. {
  13213. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13214. }
  13215. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13216. {
  13217. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13218. }
  13219. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13220. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13221. {
  13222. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13223. }
  13224. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13225. {
  13226. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13227. }
  13228. }
  13229. json_object_put(GetLog);
  13230. /*
  13231. * TODO: Upload log process
  13232. */
  13233. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13234. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13235. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13236. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13237. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13238. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13239. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13240. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13241. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13242. sendGetLogConfirmation(uuid);
  13243. return result;
  13244. }
  13245. int handleInstallCertificateRequest(char *uuid, char *payload)
  13246. {
  13247. mtrace();
  13248. int result = PASS;
  13249. json_object *InstallCertificate;
  13250. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13251. InstallCertificate = json_tokener_parse(payload);
  13252. if(!is_error(InstallCertificate))
  13253. {
  13254. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13255. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13256. /*
  13257. * TODO: Install certificate process
  13258. */
  13259. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13260. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13261. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13262. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13263. sendInstallCertificateConfirmation(uuid);
  13264. }
  13265. json_object_put(InstallCertificate);
  13266. return result;
  13267. }
  13268. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13269. {
  13270. mtrace();
  13271. int result = PASS;
  13272. json_object *SignedUpdateFirmware;
  13273. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13274. SignedUpdateFirmware = json_tokener_parse(payload);
  13275. if(!is_error(SignedUpdateFirmware))
  13276. {
  13277. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13278. {
  13279. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13280. }
  13281. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13282. {
  13283. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13284. }
  13285. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13286. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13287. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13288. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13289. {
  13290. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13291. }
  13292. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13293. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13294. }
  13295. json_object_put(SignedUpdateFirmware);
  13296. /*
  13297. * TODO: Upgrade firmware process
  13298. */
  13299. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13300. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13301. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13302. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13303. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13304. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13305. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13306. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13307. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13308. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13309. sendInstallCertificateConfirmation(uuid);
  13310. return result;
  13311. }
  13312. int handleUnknownRequest(char *uuid, char *payload)
  13313. {
  13314. mtrace();
  13315. int result = PASS;
  13316. DEBUG_INFO("handleUnknownRequest...\n");
  13317. sendUnknownConfirmation(uuid);
  13318. result = PASS;
  13319. return result;
  13320. }
  13321. //==========================================
  13322. // Handle server response routine
  13323. //==========================================
  13324. void handleAuthorizeResponse(char *payload, int gun_index)
  13325. {
  13326. mtrace();
  13327. char expiryDatestr[36]={0};
  13328. char parentIdTagstr[21]={0};
  13329. char statusstr[20]={0};
  13330. int expiryDateISNULL=FALSE;
  13331. int parentIdTagISNULL=FALSE;
  13332. DEBUG_INFO("handleAuthorizeResponse...\n");
  13333. json_object *Authorize;
  13334. Authorize = json_tokener_parse(payload);
  13335. if(!is_error(Authorize))
  13336. {
  13337. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13338. {
  13339. // Required data
  13340. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13341. // Optional data
  13342. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13343. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13344. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13345. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13346. }
  13347. }
  13348. json_object_put(Authorize);
  13349. if(expiryDateISNULL == FALSE)
  13350. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13351. if(parentIdTagISNULL == FALSE)
  13352. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13353. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13354. //Update idTag information to authorization cache if supproted
  13355. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13356. {
  13357. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13358. }
  13359. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13360. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13361. authorizeRetryTimes = 0;
  13362. }
  13363. void handleBootNotificationResponse(char *payload, int gun_index)
  13364. {
  13365. mtrace();
  13366. char statusStr[12]={0};
  13367. char currentTimeStr[30]={0};
  13368. int intervalInt = 0;
  13369. DEBUG_INFO("handleBootNotificationResponse...\n");
  13370. json_object *BootNotification;
  13371. BootNotification = json_tokener_parse(payload);
  13372. if(!is_error(BootNotification))
  13373. {
  13374. // Required data
  13375. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13376. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13377. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13378. }
  13379. json_object_put(BootNotification);
  13380. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13381. BootNotificationInterval = intervalInt;
  13382. //write back to ShmOCPP16DataPH->BootNotification
  13383. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13384. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13385. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13386. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13387. {
  13388. BootNotificationInterval = 0;
  13389. if((intervalInt == 0) || (intervalInt >= 10))
  13390. {
  13391. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13392. HeartBeatWaitTime = intervalInt;
  13393. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13394. }
  13395. server_sign = TRUE;
  13396. server_pending =FALSE;
  13397. }
  13398. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13399. {
  13400. server_pending = TRUE;
  13401. }
  13402. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13403. srand(time(NULL));
  13404. refreshStartTimer(&clientTime.Heartbeat);
  13405. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13406. SetOcppConnStatus(TRUE);
  13407. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13408. }
  13409. void handleDataTransferResponse(char *payload, int gun_index)
  13410. {
  13411. json_object *DataTransfer = json_tokener_parse(payload);
  13412. if(!is_error(DataTransfer))
  13413. {
  13414. // Required data
  13415. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13416. // Optional data
  13417. if(json_object_object_get(DataTransfer, "data") != NULL)
  13418. {
  13419. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13420. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13421. if(!is_error(Data))
  13422. {
  13423. if(json_object_object_get(Data, "msgId") != NULL)
  13424. {
  13425. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13426. {
  13427. 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")));
  13428. }
  13429. }
  13430. }
  13431. json_object_put(Data);
  13432. }
  13433. }
  13434. json_object_put(DataTransfer);
  13435. }
  13436. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13437. {
  13438. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13439. //struct json_object *obj;
  13440. // obj = json_tokener_parse(payload);
  13441. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13442. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13443. //No fields are defined.
  13444. }
  13445. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13446. {
  13447. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13448. //struct json_object *obj;
  13449. // obj = json_tokener_parse(payload);
  13450. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13451. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13452. //No fields are defined.
  13453. }
  13454. void handleHeartbeatResponse(char *payload, int gun_index)
  13455. {
  13456. mtrace();
  13457. DEBUG_INFO("handleHeartbeatResponse...\n");
  13458. json_object *Heartbeat;
  13459. Heartbeat = json_tokener_parse(payload);
  13460. if(!is_error(Heartbeat))
  13461. {
  13462. // Required data
  13463. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13464. }
  13465. json_object_put(Heartbeat);
  13466. if(FirstHeartBeat == 0)
  13467. {
  13468. FirstHeartBeat = 1;
  13469. DEBUG_INFO("FirstHeartBeat \n");
  13470. }
  13471. HeartBeatWithNOResponse = 0;
  13472. refreshStartTimer(&clientTime.Heartbeat);
  13473. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13474. }
  13475. void handleMeterValuesResponse(char *payload, int gun_index)
  13476. {
  13477. mtrace();
  13478. DEBUG_INFO("handleMeterValuesResponse...\n");
  13479. isQueueSendable = 1;
  13480. }
  13481. void handleStartTransactionResponse(char *payload, int gun_index)
  13482. {
  13483. mtrace();
  13484. //int transactionIdInt = 0;
  13485. FILE *outfile;
  13486. char data[100]={0};
  13487. DEBUG_INFO("handleStartTransactionResponse...\n");
  13488. json_object *StartTransaction;
  13489. StartTransaction = json_tokener_parse(payload);
  13490. if(!is_error(StartTransaction))
  13491. {
  13492. // Required data
  13493. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13494. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13495. // Optional data
  13496. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13497. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13498. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13499. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13500. }
  13501. json_object_put(StartTransaction);
  13502. isQueueSendable = 1;
  13503. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13504. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13505. //-----------Start : write to the Queue TransactionId file -----------------//
  13506. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13507. {}
  13508. else
  13509. {
  13510. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13511. if(log == NULL)
  13512. {
  13513. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13514. return ;
  13515. }
  13516. else
  13517. {
  13518. fclose(log);
  13519. }
  13520. }
  13521. // open file for writing
  13522. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13523. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13524. {
  13525. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13526. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13527. fputs(data, outfile);
  13528. fclose (outfile);
  13529. }
  13530. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13531. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13532. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13533. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13534. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13535. }
  13536. void handleStatusNotificationResponse(char *payload, int gun_index)
  13537. {
  13538. mtrace();
  13539. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13540. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13541. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13542. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13543. }
  13544. void handleStopTransactionnResponse(char *payload, int gun_index)
  13545. {
  13546. mtrace();
  13547. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13548. json_object *StopTransaction;
  13549. StopTransaction = json_tokener_parse(payload);
  13550. if(!is_error(StopTransaction))
  13551. {
  13552. // Optional data
  13553. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13554. {
  13555. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13556. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13557. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13558. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13559. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13560. }
  13561. }
  13562. json_object_put(StopTransaction);
  13563. isQueueSendable = 1;
  13564. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13565. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13566. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13567. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13568. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13569. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13570. }
  13571. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13572. {
  13573. mtrace();
  13574. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13575. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13576. }
  13577. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13578. {
  13579. mtrace();
  13580. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13581. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13582. }
  13583. void handleSignCertificateResponse(char *payload, int gun_index)
  13584. {
  13585. mtrace();
  13586. DEBUG_INFO("handleSignCertificateResponse...\n");
  13587. json_object *SignCertificate;
  13588. SignCertificate = json_tokener_parse(payload);
  13589. if(!is_error(SignCertificate))
  13590. {
  13591. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13592. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13593. }
  13594. json_object_put(SignCertificate);
  13595. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13596. }
  13597. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13598. {
  13599. mtrace();
  13600. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13601. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13602. }
  13603. //==========================================
  13604. // Handle Error routine
  13605. //==========================================
  13606. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13607. {
  13608. mtrace();
  13609. #ifdef SystemLogMessage
  13610. DEBUG_INFO("errorCode: %s\n", errorCode);
  13611. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13612. DEBUG_INFO("errorDetails: %s\n", payload);
  13613. #endif
  13614. }
  13615. //===============================================
  13616. // Common routine
  13617. //===============================================
  13618. int initialConfigurationTable(void)
  13619. {
  13620. //clock_t start_t, end_t, total_t;
  13621. FILE *fp;
  13622. FILE *outfile;
  13623. char str[512]={0};
  13624. char sstr[256]={0};
  13625. int c = 0;
  13626. char *loc;
  13627. int confVersion = 18;
  13628. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13629. //start_t = clock();
  13630. //printf("Starting of the program, start_t = %ld\n", start_t);
  13631. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13632. // Check configuration file size is correct
  13633. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13634. {
  13635. struct stat st;
  13636. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13637. if(st.st_size < 3100)
  13638. {
  13639. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13640. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13641. }
  13642. }
  13643. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13644. {
  13645. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13646. if(outfile == NULL)
  13647. {
  13648. DEBUG_INFO("Error opening file\n");
  13649. return FALSE;
  13650. }
  13651. /*Core Profile*/
  13652. //AllowOfflineTxForUnknownId
  13653. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13654. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13655. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13657. //AuthorizationCacheEnabled
  13658. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13659. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13660. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13662. //AuthorizeRemoteTxRequests
  13663. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13664. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13665. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13667. //BlinkRepeat
  13668. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13669. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13670. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13672. //ClockAlignedDataInterval
  13673. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13674. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13675. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13677. //ConnectionTimeOut
  13678. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13679. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13680. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13682. //GetConfigurationMaxKeys
  13683. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13684. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13687. // HeartbeatInterval
  13688. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13689. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13690. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13692. // LightIntensity
  13693. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13694. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13695. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13697. // LocalAuthorizeOffline
  13698. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13699. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13700. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13702. // LocalPreAuthorize
  13703. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13704. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13705. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13707. // MaxEnergyOnInvalidId
  13708. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13709. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13710. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13712. // MeterValuesAlignedData
  13713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13714. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13715. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13716. 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" );
  13717. else
  13718. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13720. // MeterValuesAlignedDataMaxLength
  13721. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13722. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13723. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13724. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13725. else
  13726. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13728. // MeterValuesSampledData
  13729. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13730. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13731. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13732. 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" );
  13733. else
  13734. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13736. // MeterValuesSampledDataMaxLength
  13737. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13738. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13740. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13741. else
  13742. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13744. // MeterValueSampleInterval
  13745. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13746. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13747. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13749. // MinimumStatusDuration
  13750. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13751. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13752. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13753. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13755. // NumberOfConnectors
  13756. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13757. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13758. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13759. {
  13760. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13761. }
  13762. else
  13763. {
  13764. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13765. }
  13766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13767. // ResetRetries
  13768. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13769. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13770. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13772. // ConnectorPhaseRotation
  13773. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13774. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13775. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13777. // ConnectorPhaseRotationMaxLength
  13778. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13779. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13780. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13782. // StopTransactionOnEVSideDisconnect
  13783. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13784. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13785. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13787. // StopTransactionOnInvalidId
  13788. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13789. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13790. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13792. // StopTxnAlignedData
  13793. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13794. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13795. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13797. // StopTxnAlignedDataMaxLength
  13798. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13799. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13800. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13802. // StopTxnSampledData
  13803. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13804. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13805. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13806. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13807. else
  13808. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13810. // StopTxnSampledDataMaxLength
  13811. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13812. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13813. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13814. {
  13815. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13816. }
  13817. else
  13818. {
  13819. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13820. }
  13821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13822. // SupportedFeatureProfiles
  13823. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13824. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13825. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13827. // SupportedFeatureProfilesMaxLength
  13828. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13832. // TransactionMessageAttempts
  13833. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13834. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13835. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13836. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13838. // TransactionMessageRetryInterval
  13839. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13841. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13842. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13844. // UnlockConnectorOnEVSideDisconnect
  13845. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13846. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13849. // WebSocketPingInterval
  13850. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13852. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13854. // QueueOffLineMeterValues
  13855. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13856. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13857. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13859. // AuthorizationKey
  13860. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13862. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13864. // SecurityProfile
  13865. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13867. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13869. // DefaultPrice
  13870. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13871. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13874. // CustomDisplayCostAndPrice
  13875. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13877. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13879. // CustomIdleFeeAfterStop
  13880. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13881. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13884. // SystemUptimeSec
  13885. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13886. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13889. // FreeVend
  13890. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13891. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13892. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13894. // FreeVendIdtag
  13895. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13899. // OcppServer
  13900. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13901. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13902. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13904. // MaintainServer
  13905. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13906. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13907. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13909. // StatusNotificationPeriodically
  13910. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13911. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13912. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13914. // StatusNotificationInterval
  13915. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13916. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13917. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13919. // isEnableLocalPowerSharing
  13920. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  13921. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  13922. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  13923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  13924. // PowerSharingServerIP
  13925. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  13926. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  13927. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  13928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  13929. // EVCCID_PREFIX
  13930. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  13931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  13932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  13933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  13934. // OffLineMaxChargingPower
  13935. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  13936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  13937. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  13938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  13939. // Configuration Version
  13940. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13941. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13942. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13944. // Charging profile refresh interval
  13945. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  13946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  13947. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  13948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  13949. // Ocpp Software certificated version
  13950. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  13951. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  13952. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  13953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  13954. //* Local Auth List Management Profile*/
  13955. #if 0
  13956. //For OCTT Test Case
  13957. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13958. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13959. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13960. #endif
  13961. #if 1
  13962. //LocalAuthListEnabled
  13963. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13965. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13967. #endif
  13968. //LocalAuthListMaxLength
  13969. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13973. //SendLocalListMaxLength
  13974. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13975. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13976. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  13977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13978. //ReserveConnectorZeroSupported
  13979. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13982. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13983. //* Smart Charging Profile */
  13984. //ChargeProfileMaxStackLevel
  13985. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13987. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  13988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13989. // ChargingScheduleAllowedChargingRateUnit
  13990. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13991. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13994. // ChargingScheduleMaxPeriods
  13995. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13997. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13999. // ConnectorSwitch3to1PhaseSupported
  14000. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14004. // MaxChargingProfilesInstalled
  14005. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14009. fclose(outfile);
  14010. }
  14011. else
  14012. {
  14013. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  14014. char keystr[60]={0};
  14015. char readonlystr[10]={0};
  14016. char valuestr[256]={0};
  14017. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  14018. if(fp == NULL) {
  14019. DEBUG_INFO("Error opening file");
  14020. return FALSE;
  14021. }
  14022. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14023. {
  14024. //DEBUG_INFO("Get Configuration \n");
  14025. if(strlen(str) > 0)
  14026. {
  14027. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14028. //*************************key*********************************/
  14029. if(strstr(str, "key") != NULL)
  14030. {
  14031. loc = strstr(str, "key");
  14032. c = 0;
  14033. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14034. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14035. {
  14036. sstr[c] = loc[strlen("key")+3+c];
  14037. c++;
  14038. }
  14039. sstr[c] = '\0';
  14040. strcpy(keystr,sstr);
  14041. }
  14042. //*************************readonly*********************************/
  14043. if(strstr(str, "readonly") != NULL)
  14044. {
  14045. loc = strstr(str, "readonly");
  14046. c = 0;
  14047. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14048. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14049. {
  14050. sstr[c] = loc[strlen("readonly")+2+c];
  14051. c++;
  14052. }
  14053. sstr[c] = '\0';
  14054. strcpy(readonlystr,sstr);
  14055. }
  14056. //*************************value*********************************/
  14057. if(strstr(str, "value") != NULL)
  14058. {
  14059. loc = strstr(str, "value");
  14060. c = 0;
  14061. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14062. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14063. {
  14064. sstr[c] = loc[strlen("value")+3+c];
  14065. c++;
  14066. }
  14067. sstr[c] = '\0';
  14068. strcpy(valuestr,sstr);
  14069. }
  14070. // DEBUG_INFO("keystr=%s\n",keystr);
  14071. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14072. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14073. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14074. {
  14075. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14076. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14077. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14078. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14079. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14080. }
  14081. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14082. {
  14083. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14084. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14085. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14086. }
  14087. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14088. {
  14089. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14090. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14091. }
  14092. if(strcmp(keystr, "BlinkRepeat") == 0)
  14093. {
  14094. //Charger.BlinkRepeat = Integer.parseInt(value);
  14095. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14096. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14097. }
  14098. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14099. {
  14100. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14101. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14102. }
  14103. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14104. {
  14105. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14106. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14107. }
  14108. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14109. {
  14110. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14111. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14112. }
  14113. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14114. {
  14115. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14116. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14117. HeartBeatWaitTime = atoi(valuestr);
  14118. }
  14119. if(strcmp(keystr, "LightIntensity") == 0)
  14120. {
  14121. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14122. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14123. }
  14124. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14125. {
  14126. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14127. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14128. }
  14129. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14130. {
  14131. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14132. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14133. }
  14134. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14135. {
  14136. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14137. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14138. }
  14139. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14140. {
  14141. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14142. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14143. }
  14144. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14145. {
  14146. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14147. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14148. }
  14149. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14150. {
  14151. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14152. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14153. }
  14154. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14155. {
  14156. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14157. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14158. }
  14159. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14160. {
  14161. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14162. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14163. }
  14164. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14165. {
  14166. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14167. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14168. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14169. }
  14170. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14171. {
  14172. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14173. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14174. }
  14175. if(strcmp(keystr, "ResetRetries") == 0)
  14176. {
  14177. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14178. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14179. }
  14180. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14181. {
  14182. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14183. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14184. }
  14185. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14186. {
  14187. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14188. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14189. }
  14190. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14191. {
  14192. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14193. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14194. }
  14195. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14196. {
  14197. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14198. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14199. }
  14200. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14201. {
  14202. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14203. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14204. }
  14205. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14206. {
  14207. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14208. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14209. }
  14210. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14211. {
  14212. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14213. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14214. }
  14215. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14216. {
  14217. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14218. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14219. }
  14220. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14221. {
  14222. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14223. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14224. }
  14225. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14226. {
  14227. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14228. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14229. }
  14230. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14231. {
  14232. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14233. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14234. TransactionMessageAttemptsValue = atoi(valuestr);
  14235. }
  14236. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14237. {
  14238. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14239. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14240. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14241. }
  14242. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14243. {
  14244. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14245. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14246. }
  14247. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14248. {
  14249. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14250. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14251. }
  14252. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14253. {
  14254. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14255. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14256. }
  14257. if(strcmp(keystr, "AuthorizationKey") == 0)
  14258. {
  14259. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14260. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14261. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14262. }
  14263. if(strcmp(keystr, "SecurityProfile") == 0)
  14264. {
  14265. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14266. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14267. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14268. }
  14269. if(strcmp(keystr, "DefaultPrice") == 0)
  14270. {
  14271. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14272. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14273. }
  14274. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14275. {
  14276. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14277. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14278. }
  14279. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14280. {
  14281. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14282. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14283. }
  14284. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14285. {
  14286. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14287. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14288. }
  14289. if(strcmp(keystr, "FreeVend") == 0)
  14290. {
  14291. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14292. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14293. }
  14294. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14295. {
  14296. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14297. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14298. }
  14299. if(strcmp(keystr, "OcppServer") == 0)
  14300. {
  14301. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14302. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14303. }
  14304. if(strcmp(keystr, "MaintainServer") == 0)
  14305. {
  14306. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14307. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14308. }
  14309. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14310. {
  14311. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14312. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14313. }
  14314. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14315. {
  14316. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14317. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14318. }
  14319. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14320. {
  14321. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14322. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14323. }
  14324. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14325. {
  14326. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14327. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14328. }
  14329. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14330. {
  14331. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14332. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14333. }
  14334. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  14335. {
  14336. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14337. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  14338. }
  14339. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14340. {
  14341. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14342. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14343. }
  14344. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  14345. {
  14346. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14347. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  14348. }
  14349. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  14350. {
  14351. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14352. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  14353. }
  14354. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14355. {
  14356. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14357. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14358. }
  14359. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14360. {
  14361. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14362. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14363. }
  14364. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14365. {
  14366. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14367. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14368. }
  14369. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14370. {
  14371. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14372. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14373. }
  14374. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14375. {
  14376. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14377. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14378. }
  14379. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14380. {
  14381. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14382. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14383. }
  14384. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14385. {
  14386. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14387. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14388. }
  14389. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14390. {
  14391. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14392. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14393. }
  14394. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14395. {
  14396. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14397. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14398. }
  14399. }
  14400. }
  14401. fclose(fp);
  14402. }
  14403. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14404. {
  14405. return PASS;
  14406. }
  14407. else
  14408. {
  14409. return FAIL;
  14410. }
  14411. }
  14412. void StoreConfigurationTable(void)
  14413. {
  14414. FILE *outfile;
  14415. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14416. if(outfile == NULL)
  14417. {
  14418. DEBUG_INFO("Error opening file");
  14419. return ;
  14420. }
  14421. /*Core Profile*/
  14422. //AllowOfflineTxForUnknownId
  14423. /*
  14424. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14425. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14426. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14428. */
  14429. //DEBUG_INFO("data=%s\n",data);
  14430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14431. //AuthorizationCacheEnabled
  14432. /*
  14433. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14434. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14435. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14436. */
  14437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14438. //AuthorizeRemoteTxRequests
  14439. /*
  14440. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14441. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14442. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14443. */
  14444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14445. //BlinkRepeat
  14446. /*
  14447. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14448. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14449. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14450. */
  14451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14452. //ClockAlignedDataInterval
  14453. /*
  14454. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14455. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14456. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14457. */
  14458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14459. //ConnectionTimeOut
  14460. /*
  14461. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14462. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14463. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14464. */
  14465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14466. //GetConfigurationMaxKeys
  14467. /*
  14468. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14469. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14470. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14471. */
  14472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14473. // HeartbeatInterval
  14474. /*
  14475. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14476. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14477. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14478. */
  14479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14480. // LightIntensity
  14481. /*
  14482. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14483. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14484. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14485. */
  14486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14487. // LocalAuthorizeOffline
  14488. /*
  14489. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14490. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14491. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14492. */
  14493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14494. // LocalPreAuthorize
  14495. /*
  14496. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14497. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14498. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14499. */
  14500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14501. // MaxEnergyOnInvalidId
  14502. /*
  14503. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14504. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14505. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14506. */
  14507. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14509. // MeterValuesAlignedData
  14510. /*
  14511. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14512. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14513. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14514. */
  14515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14516. // MeterValuesAlignedDataMaxLength
  14517. /*
  14518. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14519. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14520. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14521. */
  14522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14523. // MeterValuesSampledData
  14524. /*
  14525. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14526. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14527. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14528. */
  14529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14530. // MeterValuesSampledDataMaxLength
  14531. /*
  14532. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14533. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14534. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14535. */
  14536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14537. // MeterValueSampleInterval
  14538. /*
  14539. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14540. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14541. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14542. */
  14543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14544. // MinimumStatusDuration
  14545. /*
  14546. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14547. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14548. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14549. */
  14550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14551. // NumberOfConnectors
  14552. /*
  14553. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14554. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14556. {
  14557. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14558. }
  14559. else
  14560. {
  14561. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14562. }
  14563. */
  14564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14565. // ResetRetries
  14566. /*
  14567. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14568. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14569. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14570. */
  14571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14572. // ConnectorPhaseRotation
  14573. /*
  14574. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14575. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14576. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14577. */
  14578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14579. // ConnectorPhaseRotationMaxLength
  14580. /*
  14581. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14582. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14583. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14584. */
  14585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14586. // StopTransactionOnEVSideDisconnect
  14587. /*
  14588. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14589. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14590. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14591. */
  14592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14593. // StopTransactionOnInvalidId
  14594. /*
  14595. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14596. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14597. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14598. */
  14599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14600. // StopTxnAlignedData
  14601. /*
  14602. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14603. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14604. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14605. */
  14606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14607. // StopTxnAlignedDataMaxLength
  14608. /*
  14609. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14610. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14611. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14612. */
  14613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14614. // StopTxnSampledData
  14615. /*
  14616. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14617. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14618. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14619. */
  14620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14621. // StopTxnSampledDataMaxLength
  14622. /*
  14623. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14624. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14625. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14626. */
  14627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14628. // SupportedFeatureProfiles
  14629. /*
  14630. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14631. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14632. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14633. */
  14634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14635. // SupportedFeatureProfilesMaxLength
  14636. /*
  14637. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14638. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14639. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14640. */
  14641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14642. // TransactionMessageAttempts
  14643. /*
  14644. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14645. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14646. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14647. */
  14648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14649. // TransactionMessageRetryInterval
  14650. /*
  14651. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14652. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14653. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14654. */
  14655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14656. // UnlockConnectorOnEVSideDisconnect
  14657. /*
  14658. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14659. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14660. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14661. */
  14662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14663. // WebSocketPingInterval
  14664. /*
  14665. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14666. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14667. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14668. */
  14669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14670. // QueueOffLineMeterValues
  14671. /*
  14672. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14673. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14674. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14675. */
  14676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14677. // AuthorizationKey
  14678. /*
  14679. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14680. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14681. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14682. */
  14683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14684. // SecurityProfile
  14685. /*
  14686. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14687. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14688. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14689. */
  14690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14691. // DefaultPrice
  14692. /*
  14693. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14694. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14695. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14696. */
  14697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14698. // CustomDisplayCostAndPrice
  14699. /*
  14700. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14701. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14702. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14703. */
  14704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14705. // CustomIdleFeeAfterStop
  14706. /*
  14707. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14708. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14709. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14710. */
  14711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14712. // SystemUptimeSec
  14713. /*
  14714. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14715. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14716. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14717. */
  14718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14719. // FreeVend
  14720. /*
  14721. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14722. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14723. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14724. */
  14725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14726. // FreeVendIdtag
  14727. /*
  14728. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14729. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14730. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14731. */
  14732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14733. // OcppServer
  14734. /*
  14735. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14736. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14737. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14738. */
  14739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14740. // MaintainServer
  14741. /*
  14742. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14743. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14744. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14745. */
  14746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14747. // StatusNotificationPeriodically
  14748. /*
  14749. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14750. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14751. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14752. */
  14753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14754. // StatusNotificationInterval
  14755. /*
  14756. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14757. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14758. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14759. */
  14760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14761. // isEnableLocalPowerSharing
  14762. /*
  14763. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  14766. */
  14767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14768. // PowerSharingServerIP
  14769. /*
  14770. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  14773. */
  14774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14775. // EVCCID_PREFIX
  14776. /*
  14777. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14780. */
  14781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14782. // OffLineMaxChargingPower
  14783. /*
  14784. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  14785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  14786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  14787. */
  14788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  14789. // ConfigurationVersion
  14790. /*
  14791. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14792. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14793. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14794. */
  14795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14796. // CharingProfileRefreshInterval
  14797. /*
  14798. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  14799. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  14800. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  14801. */
  14802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  14803. // OcppSoftwareVersion
  14804. /*
  14805. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  14806. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  14807. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  14808. */
  14809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  14810. //* Local Auth List Management Profile*/
  14811. //LocalAuthListEnabled
  14812. /*
  14813. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14814. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14815. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14816. */
  14817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14818. //LocalAuthListMaxLength
  14819. /*
  14820. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14821. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14822. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14823. */
  14824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14825. //SendLocalListMaxLength
  14826. /*
  14827. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14828. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14830. */
  14831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14832. //ReserveConnectorZeroSupported
  14833. /*
  14834. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14835. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14836. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14837. */
  14838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14839. //* Smart Charging Profile */
  14840. //ChargeProfileMaxStackLevel
  14841. /*
  14842. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14843. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14845. */
  14846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14847. // ChargingScheduleAllowedChargingRateUnit
  14848. /*
  14849. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14852. */
  14853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14854. // ChargingScheduleMaxPeriods
  14855. /*
  14856. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14857. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14858. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14859. */
  14860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14861. // ConnectorSwitch3to1PhaseSupported
  14862. /*
  14863. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14864. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14866. */
  14867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14868. // MaxChargingProfilesInstalled
  14869. /*
  14870. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14871. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14873. */
  14874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14875. fclose(outfile);
  14876. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14877. }
  14878. void getKeyValue(char *keyReq)
  14879. {
  14880. int isEmpty = FALSE;
  14881. int isKnowKey = FALSE;
  14882. DEBUG_INFO("keyReq = %s\n", keyReq);
  14883. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14884. isEmpty = TRUE;
  14885. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14886. {
  14887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14889. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14890. {
  14891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14892. }
  14893. else
  14894. {
  14895. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14896. }
  14897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14898. isKnowKey = TRUE;
  14899. }
  14900. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14901. {
  14902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14904. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14905. {
  14906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14907. }
  14908. else
  14909. {
  14910. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14911. }
  14912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14913. isKnowKey = TRUE;
  14914. }
  14915. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14916. {
  14917. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14918. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14919. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14920. {
  14921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14922. }
  14923. else
  14924. {
  14925. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14926. }
  14927. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14928. isKnowKey = TRUE;
  14929. }
  14930. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14931. {
  14932. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14934. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14935. {
  14936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14937. }
  14938. else
  14939. {
  14940. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14941. }
  14942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14943. isKnowKey = TRUE;
  14944. }
  14945. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14946. {
  14947. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14949. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14950. {
  14951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14952. }
  14953. else
  14954. {
  14955. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14956. }
  14957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14958. isKnowKey = TRUE;
  14959. }
  14960. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14961. {
  14962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14963. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14964. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14965. {
  14966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14967. }
  14968. else
  14969. {
  14970. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14971. }
  14972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14973. isKnowKey = TRUE;
  14974. }
  14975. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14976. {
  14977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14978. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14979. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14980. {
  14981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14982. }
  14983. else
  14984. {
  14985. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14986. }
  14987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14988. isKnowKey = TRUE;
  14989. }
  14990. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14991. {
  14992. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14994. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14995. {
  14996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14997. }
  14998. else
  14999. {
  15000. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15001. }
  15002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15003. isKnowKey = TRUE;
  15004. }
  15005. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15006. {
  15007. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15008. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15009. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15010. {
  15011. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15012. }
  15013. else
  15014. {
  15015. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15016. }
  15017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15018. isKnowKey = TRUE;
  15019. }
  15020. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15021. {
  15022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15023. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15024. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15025. {
  15026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15027. }
  15028. else
  15029. {
  15030. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15031. }
  15032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15033. isKnowKey = TRUE;
  15034. }
  15035. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15036. {
  15037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15038. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15039. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15040. {
  15041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15042. }
  15043. else
  15044. {
  15045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15046. }
  15047. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15048. isKnowKey = TRUE;
  15049. }
  15050. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15051. {
  15052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15053. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15054. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15055. {
  15056. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15057. }
  15058. else
  15059. {
  15060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15061. }
  15062. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15063. isKnowKey = TRUE;
  15064. }
  15065. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15066. {
  15067. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15068. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15069. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15070. {
  15071. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15072. }
  15073. else
  15074. {
  15075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15076. }
  15077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15078. isKnowKey = TRUE;
  15079. }
  15080. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15081. {
  15082. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15083. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15084. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15085. {
  15086. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15087. }
  15088. else
  15089. {
  15090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15091. }
  15092. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15093. isKnowKey = TRUE;
  15094. }
  15095. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15096. {
  15097. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15098. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15099. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15100. {
  15101. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15102. }
  15103. else
  15104. {
  15105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15106. }
  15107. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15108. isKnowKey = TRUE;
  15109. }
  15110. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15111. {
  15112. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15113. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15114. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15115. {
  15116. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15117. }
  15118. else
  15119. {
  15120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15121. }
  15122. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15123. isKnowKey = TRUE;
  15124. }
  15125. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15126. {
  15127. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15128. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15129. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15130. {
  15131. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15132. }
  15133. else
  15134. {
  15135. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15136. }
  15137. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15138. isKnowKey = TRUE;
  15139. }
  15140. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15141. {
  15142. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15143. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15144. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15145. {
  15146. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15147. }
  15148. else
  15149. {
  15150. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15151. }
  15152. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  15153. isKnowKey = TRUE;
  15154. }
  15155. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15156. {
  15157. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15158. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15159. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15160. {
  15161. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15162. }
  15163. else
  15164. {
  15165. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15166. }
  15167. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15168. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15169. isKnowKey = TRUE;
  15170. }
  15171. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15172. {
  15173. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15174. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15175. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15176. {
  15177. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15178. }
  15179. else
  15180. {
  15181. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15182. }
  15183. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15184. isKnowKey = TRUE;
  15185. }
  15186. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15187. {
  15188. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15189. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15190. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15191. {
  15192. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15193. }
  15194. else
  15195. {
  15196. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15197. }
  15198. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15199. isKnowKey = TRUE;
  15200. }
  15201. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15202. {
  15203. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15204. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15205. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15206. {
  15207. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15208. }
  15209. else
  15210. {
  15211. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15212. }
  15213. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15214. isKnowKey = TRUE;
  15215. }
  15216. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15217. {
  15218. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15219. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15220. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15221. {
  15222. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15223. }
  15224. else
  15225. {
  15226. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15227. }
  15228. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15229. isKnowKey = TRUE;
  15230. }
  15231. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15232. {
  15233. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15234. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15235. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15236. {
  15237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15238. }
  15239. else
  15240. {
  15241. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15242. }
  15243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15244. isKnowKey = TRUE;
  15245. }
  15246. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15247. {
  15248. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15249. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15250. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15251. {
  15252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15253. }
  15254. else
  15255. {
  15256. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15257. }
  15258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15259. isKnowKey = TRUE;
  15260. }
  15261. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15262. {
  15263. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15264. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15265. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15266. {
  15267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15268. }
  15269. else
  15270. {
  15271. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15272. }
  15273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15274. isKnowKey = TRUE;
  15275. }
  15276. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15277. {
  15278. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15279. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15280. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15281. {
  15282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15283. }
  15284. else
  15285. {
  15286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15287. }
  15288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15289. isKnowKey = TRUE;
  15290. }
  15291. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15292. {
  15293. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15294. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15295. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15296. {
  15297. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15298. }
  15299. else
  15300. {
  15301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15302. }
  15303. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15304. isKnowKey = TRUE;
  15305. }
  15306. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15307. {
  15308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15310. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15311. {
  15312. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15313. }
  15314. else
  15315. {
  15316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15317. }
  15318. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15319. isKnowKey = TRUE;
  15320. }
  15321. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15322. {
  15323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15325. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15326. {
  15327. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15328. }
  15329. else
  15330. {
  15331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15332. }
  15333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15334. isKnowKey = TRUE;
  15335. }
  15336. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15337. {
  15338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15340. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15341. {
  15342. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15343. }
  15344. else
  15345. {
  15346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15347. }
  15348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15349. isKnowKey = TRUE;
  15350. }
  15351. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15352. {
  15353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15355. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15356. {
  15357. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15358. }
  15359. else
  15360. {
  15361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15362. }
  15363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15364. isKnowKey = TRUE;
  15365. }
  15366. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15367. {
  15368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15370. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15371. {
  15372. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15373. }
  15374. else
  15375. {
  15376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15377. }
  15378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15379. isKnowKey = TRUE;
  15380. }
  15381. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15382. {
  15383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15385. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15386. {
  15387. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15388. }
  15389. else
  15390. {
  15391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15392. }
  15393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15394. isKnowKey = TRUE;
  15395. }
  15396. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15397. {
  15398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15400. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15401. {
  15402. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15403. }
  15404. else
  15405. {
  15406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15407. }
  15408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15409. isKnowKey = TRUE;
  15410. }
  15411. /*
  15412. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15413. {
  15414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15416. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15417. {
  15418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15419. }
  15420. else
  15421. {
  15422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15423. }
  15424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15425. isKnowKey = TRUE;
  15426. }*/
  15427. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15428. {
  15429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15431. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15432. {
  15433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15434. }
  15435. else
  15436. {
  15437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15438. }
  15439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15440. isKnowKey = TRUE;
  15441. }
  15442. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15443. {
  15444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15446. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15447. {
  15448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15449. }
  15450. else
  15451. {
  15452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15453. }
  15454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15455. isKnowKey = TRUE;
  15456. }
  15457. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15458. {
  15459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15461. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15462. {
  15463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15464. }
  15465. else
  15466. {
  15467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15468. }
  15469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15470. isKnowKey = TRUE;
  15471. }
  15472. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15473. {
  15474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15476. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15477. {
  15478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15479. }
  15480. else
  15481. {
  15482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15483. }
  15484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15485. isKnowKey = TRUE;
  15486. }
  15487. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15488. {
  15489. struct sysinfo s_info;
  15490. int error = sysinfo(&s_info);
  15491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15493. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15494. {
  15495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15496. }
  15497. else
  15498. {
  15499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15500. }
  15501. if(error != 0)
  15502. {
  15503. DEBUG_WARN("System uptime get error: %d\n", error);
  15504. }
  15505. else
  15506. {
  15507. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15508. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15509. }
  15510. isKnowKey = TRUE;
  15511. }
  15512. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15513. {
  15514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15516. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15517. {
  15518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15519. }
  15520. else
  15521. {
  15522. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15523. }
  15524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15525. isKnowKey = TRUE;
  15526. }
  15527. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15528. {
  15529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15531. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15532. {
  15533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15534. }
  15535. else
  15536. {
  15537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15538. }
  15539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15540. isKnowKey = TRUE;
  15541. }
  15542. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15543. {
  15544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15546. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15547. {
  15548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15549. }
  15550. else
  15551. {
  15552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15553. }
  15554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15555. isKnowKey = TRUE;
  15556. }
  15557. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15558. {
  15559. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15561. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15562. {
  15563. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15564. }
  15565. else
  15566. {
  15567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15568. }
  15569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15570. isKnowKey = TRUE;
  15571. }
  15572. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15573. {
  15574. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15576. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15577. {
  15578. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15579. }
  15580. else
  15581. {
  15582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15583. }
  15584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15585. isKnowKey = TRUE;
  15586. }
  15587. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15588. {
  15589. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15591. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15592. {
  15593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15594. }
  15595. else
  15596. {
  15597. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15598. }
  15599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15600. isKnowKey = TRUE;
  15601. }
  15602. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  15603. {
  15604. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  15605. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  15606. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  15607. {
  15608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  15609. }
  15610. else
  15611. {
  15612. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  15613. }
  15614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  15615. isKnowKey = TRUE;
  15616. }
  15617. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  15618. {
  15619. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  15620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  15621. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  15622. {
  15623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  15624. }
  15625. else
  15626. {
  15627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  15628. }
  15629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  15630. isKnowKey = TRUE;
  15631. }
  15632. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  15633. {
  15634. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  15635. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  15636. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  15637. {
  15638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  15639. }
  15640. else
  15641. {
  15642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  15643. }
  15644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  15645. isKnowKey = TRUE;
  15646. }
  15647. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  15648. {
  15649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  15650. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  15651. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  15652. {
  15653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  15654. }
  15655. else
  15656. {
  15657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  15658. }
  15659. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  15660. isKnowKey = TRUE;
  15661. }
  15662. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15663. {
  15664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15665. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15666. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15667. {
  15668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15669. }
  15670. else
  15671. {
  15672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15673. }
  15674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15675. isKnowKey = TRUE;
  15676. }
  15677. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  15678. {
  15679. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  15680. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  15681. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  15682. {
  15683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  15684. }
  15685. else
  15686. {
  15687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  15688. }
  15689. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  15690. isKnowKey = TRUE;
  15691. }
  15692. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  15693. {
  15694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  15695. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  15696. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  15697. {
  15698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  15699. }
  15700. else
  15701. {
  15702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  15703. }
  15704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  15705. isKnowKey = TRUE;
  15706. }
  15707. #if 1
  15708. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15709. {
  15710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15712. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15713. {
  15714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15715. }
  15716. else
  15717. {
  15718. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15719. }
  15720. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15721. isKnowKey = TRUE;
  15722. }
  15723. #endif
  15724. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15725. {
  15726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15727. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15728. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15729. {
  15730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15731. }
  15732. else
  15733. {
  15734. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15735. }
  15736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15737. isKnowKey = TRUE;
  15738. }
  15739. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15740. {
  15741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15742. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15743. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15744. {
  15745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15746. }
  15747. else
  15748. {
  15749. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15750. }
  15751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15752. isKnowKey = TRUE;
  15753. }
  15754. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15755. {
  15756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15757. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15758. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15759. {
  15760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15761. }
  15762. else
  15763. {
  15764. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15765. }
  15766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15767. isKnowKey = TRUE;
  15768. }
  15769. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15770. {
  15771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15772. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15773. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15774. {
  15775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15776. }
  15777. else
  15778. {
  15779. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15780. }
  15781. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15782. isKnowKey = TRUE;
  15783. }
  15784. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15785. {
  15786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15787. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15788. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15789. {
  15790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15791. }
  15792. else
  15793. {
  15794. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15795. }
  15796. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15797. isKnowKey = TRUE;
  15798. }
  15799. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15800. {
  15801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15802. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15803. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15804. {
  15805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15806. }
  15807. else
  15808. {
  15809. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15810. }
  15811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15812. isKnowKey = TRUE;
  15813. }
  15814. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15815. {
  15816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15817. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15818. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15819. {
  15820. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15821. }
  15822. else
  15823. {
  15824. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15825. }
  15826. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15827. isKnowKey = TRUE;
  15828. }
  15829. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15830. {
  15831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15832. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15833. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15834. {
  15835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15836. }
  15837. else
  15838. {
  15839. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15840. }
  15841. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15842. isKnowKey = TRUE;
  15843. }
  15844. //=========================================================
  15845. if(!isEmpty && !isKnowKey)
  15846. {
  15847. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15848. strcpy(unknownkey[UnknownKeynum], keyReq);
  15849. UnknownKeynum = UnknownKeynum + 1;
  15850. }
  15851. }
  15852. void processUnkownKey(void)
  15853. {
  15854. DEBUG_INFO("processUnkownKey...\n");
  15855. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15856. for(int index=0; index < UnknownKeynum; index++)
  15857. {
  15858. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15859. {
  15860. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15861. }
  15862. }
  15863. }
  15864. int setKeyValue(char *key, char *value)
  15865. {
  15866. int isSuccess = NotSupported;
  15867. int check_ascii=0;
  15868. char str[501]={0};
  15869. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15870. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15871. {
  15872. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15873. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15874. {
  15875. strcpy(str, (const char*)value);
  15876. for(int i = 0; str[i]; i++){
  15877. str[i] = tolower(str[i]);
  15878. }
  15879. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15880. isSuccess = ConfigurationStatus_Accepted;
  15881. }
  15882. else
  15883. {
  15884. isSuccess = ConfigurationStatus_Rejected;
  15885. }
  15886. }
  15887. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15888. {
  15889. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15890. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15891. {
  15892. strcpy(str, (const char*)value);
  15893. for(int i = 0; str[i]; i++){
  15894. str[i] = tolower(str[i]);
  15895. }
  15896. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15897. isSuccess = ConfigurationStatus_Accepted;
  15898. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15899. }
  15900. else
  15901. {
  15902. isSuccess = ConfigurationStatus_Rejected;
  15903. }
  15904. }
  15905. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15906. {
  15907. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15908. {
  15909. strcpy(str, (const char*)value);
  15910. for(int i = 0; str[i]; i++)
  15911. {
  15912. str[i] = tolower(str[i]);
  15913. }
  15914. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15915. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15916. isSuccess = ConfigurationStatus_Accepted;
  15917. }
  15918. else
  15919. {
  15920. isSuccess = ConfigurationStatus_Rejected;
  15921. }
  15922. }
  15923. if(strcmp(key, "BlinkRepeat") == 0)
  15924. {
  15925. //Charger.BlinkRepeat = Integer.parseInt(value);
  15926. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15927. {
  15928. check_ascii = value[0];
  15929. if( (check_ascii < 48) || (check_ascii > 57) )
  15930. {
  15931. isSuccess = ConfigurationStatus_Rejected;
  15932. }
  15933. else
  15934. {
  15935. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15936. isSuccess = ConfigurationStatus_Accepted;
  15937. }
  15938. }
  15939. else
  15940. {
  15941. isSuccess = ConfigurationStatus_Rejected;
  15942. }
  15943. }
  15944. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15945. {
  15946. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15947. {
  15948. check_ascii = value[0];
  15949. if( (check_ascii < 48) || (check_ascii > 57) )
  15950. {
  15951. isSuccess = ConfigurationStatus_Rejected;
  15952. }
  15953. else
  15954. {
  15955. if((atoi(value) == 0) || (atoi(value) >= 5))
  15956. {
  15957. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15958. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15959. isSuccess = ConfigurationStatus_Accepted;
  15960. }
  15961. else
  15962. isSuccess = ConfigurationStatus_Rejected;
  15963. }
  15964. }
  15965. else
  15966. {
  15967. isSuccess = ConfigurationStatus_Rejected;
  15968. }
  15969. }
  15970. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15971. {
  15972. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15973. {
  15974. check_ascii = value[0];
  15975. if( (check_ascii < 48) || (check_ascii > 57) )
  15976. {
  15977. isSuccess = ConfigurationStatus_Rejected;
  15978. }
  15979. else
  15980. {
  15981. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15982. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15983. isSuccess = ConfigurationStatus_Accepted;
  15984. }
  15985. }
  15986. else
  15987. {
  15988. isSuccess = ConfigurationStatus_Rejected;
  15989. }
  15990. }
  15991. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15992. {
  15993. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15994. {
  15995. check_ascii = value[0];
  15996. if( (check_ascii < 48) || (check_ascii > 57) )
  15997. {
  15998. isSuccess = ConfigurationStatus_Rejected;
  15999. }
  16000. else
  16001. {
  16002. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16003. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16004. isSuccess = ConfigurationStatus_Accepted;
  16005. }
  16006. }
  16007. else
  16008. {
  16009. isSuccess = ConfigurationStatus_Rejected;
  16010. }
  16011. }
  16012. if(strcmp(key, "HeartbeatInterval") == 0)
  16013. {
  16014. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16015. {
  16016. check_ascii = value[0];
  16017. if( (check_ascii < 48) || (check_ascii > 57) )
  16018. {
  16019. isSuccess = ConfigurationStatus_Rejected;
  16020. }
  16021. else
  16022. {
  16023. if((atoi(value) == 0) || (atoi(value) >= 10))
  16024. {
  16025. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16026. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16027. HeartBeatWaitTime = atoi(value);
  16028. isSuccess = ConfigurationStatus_Accepted;
  16029. }
  16030. else
  16031. {
  16032. isSuccess = ConfigurationStatus_Rejected;
  16033. }
  16034. }
  16035. }
  16036. else
  16037. {
  16038. isSuccess = ConfigurationStatus_Rejected;
  16039. }
  16040. }
  16041. if(strcmp(key, "LightIntensity") == 0)
  16042. {
  16043. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16044. {
  16045. check_ascii = value[0];
  16046. if( (check_ascii < 48) || (check_ascii > 57) )
  16047. {
  16048. isSuccess = ConfigurationStatus_Rejected;
  16049. }
  16050. else
  16051. {
  16052. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16053. isSuccess = ConfigurationStatus_Accepted;
  16054. }
  16055. }
  16056. else
  16057. {
  16058. isSuccess = ConfigurationStatus_Rejected;
  16059. }
  16060. }
  16061. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16062. {
  16063. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16064. {
  16065. strcpy(str, (const char*)value);
  16066. for(int i = 0; str[i]; i++)
  16067. {
  16068. str[i] = tolower(str[i]);
  16069. }
  16070. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16071. isSuccess = ConfigurationStatus_Accepted;
  16072. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16073. }
  16074. else
  16075. {
  16076. isSuccess = ConfigurationStatus_Rejected;
  16077. }
  16078. }
  16079. if(strcmp(key, "LocalPreAuthorize") == 0)
  16080. {
  16081. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16082. {
  16083. strcpy(str, (const char*)value);
  16084. for(int i = 0; str[i]; i++)
  16085. {
  16086. str[i] = tolower(str[i]);
  16087. }
  16088. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16089. isSuccess = ConfigurationStatus_Accepted;
  16090. }
  16091. else
  16092. {
  16093. isSuccess = ConfigurationStatus_Rejected;
  16094. }
  16095. }
  16096. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16097. {
  16098. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16099. {
  16100. check_ascii = value[0];
  16101. if( (check_ascii < 48) || (check_ascii > 57) )
  16102. {
  16103. isSuccess = ConfigurationStatus_Rejected;
  16104. }
  16105. else
  16106. {
  16107. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16108. isSuccess = ConfigurationStatus_Accepted;
  16109. }
  16110. }
  16111. else
  16112. {
  16113. isSuccess = ConfigurationStatus_Rejected;
  16114. }
  16115. }
  16116. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16117. {
  16118. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16119. {
  16120. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16121. isSuccess = ConfigurationStatus_Accepted;
  16122. }
  16123. else
  16124. {
  16125. isSuccess = ConfigurationStatus_Rejected;
  16126. }
  16127. }
  16128. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16129. {
  16130. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16131. {
  16132. check_ascii = value[0];
  16133. if( (check_ascii < 48) || (check_ascii > 57) )
  16134. {
  16135. isSuccess = ConfigurationStatus_Rejected;
  16136. }
  16137. else
  16138. {
  16139. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16140. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16141. isSuccess = ConfigurationStatus_Accepted;
  16142. }
  16143. }
  16144. else
  16145. {
  16146. isSuccess = ConfigurationStatus_Rejected;
  16147. }
  16148. }
  16149. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16150. {
  16151. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16152. {
  16153. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16154. isSuccess = ConfigurationStatus_Accepted;
  16155. }
  16156. else
  16157. {
  16158. isSuccess = ConfigurationStatus_Rejected;
  16159. }
  16160. }
  16161. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16162. {
  16163. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16164. {
  16165. check_ascii = value[0];
  16166. if( (check_ascii < 48) || (check_ascii > 57) )
  16167. {
  16168. isSuccess = ConfigurationStatus_Rejected;
  16169. }
  16170. else
  16171. {
  16172. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16173. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16174. isSuccess = ConfigurationStatus_Accepted;
  16175. }
  16176. }
  16177. else
  16178. {
  16179. isSuccess = ConfigurationStatus_Rejected;
  16180. }
  16181. }
  16182. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16183. {
  16184. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16185. {
  16186. check_ascii = value[0];
  16187. if( (check_ascii < 48) || (check_ascii > 57) )
  16188. {
  16189. isSuccess = ConfigurationStatus_Rejected;
  16190. }
  16191. else
  16192. {
  16193. if((atoi(value) == 0) || (atoi(value) >= 3))
  16194. {
  16195. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16196. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16197. isSuccess = ConfigurationStatus_Accepted;
  16198. }
  16199. else
  16200. {
  16201. isSuccess = ConfigurationStatus_Rejected;
  16202. }
  16203. }
  16204. }
  16205. else
  16206. {
  16207. isSuccess = ConfigurationStatus_Rejected;
  16208. }
  16209. }
  16210. if(strcmp(key, "MinimumStatusDuration") == 0)
  16211. {
  16212. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16213. {
  16214. check_ascii = value[0];
  16215. if( (check_ascii < 48) || (check_ascii > 57) )
  16216. {
  16217. isSuccess = ConfigurationStatus_Rejected;
  16218. }
  16219. else
  16220. {
  16221. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16222. {
  16223. isSuccess = ConfigurationStatus_Rejected;
  16224. }
  16225. else
  16226. {
  16227. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16228. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16229. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16230. isSuccess = ConfigurationStatus_Accepted;
  16231. }
  16232. }
  16233. }
  16234. else
  16235. {
  16236. isSuccess = ConfigurationStatus_Rejected;
  16237. }
  16238. }
  16239. if(strcmp(key, "NumberOfConnectors") == 0)
  16240. {
  16241. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16242. {
  16243. check_ascii = value[0];
  16244. if( (check_ascii < 48) || (check_ascii > 57) )
  16245. {
  16246. isSuccess = ConfigurationStatus_Rejected;
  16247. }
  16248. else
  16249. {
  16250. //Charger.ResetRetries = Integer.parseInt(value);
  16251. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16252. isSuccess = ConfigurationStatus_Accepted;
  16253. }
  16254. }
  16255. else
  16256. {
  16257. isSuccess = ConfigurationStatus_Rejected;
  16258. }
  16259. }
  16260. if(strcmp(key, "ResetRetries") == 0)
  16261. {
  16262. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16263. {
  16264. check_ascii = value[0];
  16265. if( (check_ascii < 48) || (check_ascii > 57) )
  16266. {
  16267. isSuccess = ConfigurationStatus_Rejected;
  16268. }
  16269. else
  16270. {
  16271. //Charger.ResetRetries = Integer.parseInt(value);
  16272. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16273. isSuccess = ConfigurationStatus_Accepted;
  16274. }
  16275. }
  16276. else
  16277. {
  16278. isSuccess = ConfigurationStatus_Rejected;
  16279. }
  16280. }
  16281. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16282. {
  16283. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16284. {
  16285. strcpy(str, (const char*)value);
  16286. for(int i = 0; str[i]; i++)
  16287. {
  16288. str[i] = tolower(str[i]);
  16289. }
  16290. if(strcmp(str, "notapplicable")== 0)
  16291. {
  16292. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16293. isSuccess = ConfigurationStatus_Accepted;
  16294. }
  16295. else if(strcmp(str, "unknown")== 0)
  16296. {
  16297. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16298. isSuccess = ConfigurationStatus_Accepted;
  16299. }
  16300. else if(strcmp(str, "rst")== 0)
  16301. {
  16302. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16303. isSuccess = ConfigurationStatus_Accepted;
  16304. }
  16305. else if(strcmp(str, "rts")== 0)
  16306. {
  16307. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16308. isSuccess = ConfigurationStatus_Accepted;
  16309. }
  16310. else if(strcmp(str, "srt")== 0)
  16311. {
  16312. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16313. isSuccess = ConfigurationStatus_Accepted;
  16314. }
  16315. else if(strcmp(str, "str")== 0)
  16316. {
  16317. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16318. isSuccess = ConfigurationStatus_Accepted;
  16319. }
  16320. else if(strcmp(str, "trs")== 0)
  16321. {
  16322. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16323. isSuccess = ConfigurationStatus_Accepted;
  16324. }
  16325. else if(strcmp(str, "tsr")== 0)
  16326. {
  16327. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16328. isSuccess = ConfigurationStatus_Accepted;
  16329. }
  16330. else
  16331. {
  16332. isSuccess = ConfigurationStatus_Rejected;
  16333. }
  16334. }
  16335. else
  16336. {
  16337. isSuccess = ConfigurationStatus_Rejected;
  16338. }
  16339. }
  16340. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16341. {
  16342. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16343. {
  16344. check_ascii = value[0];
  16345. if( (check_ascii < 48) || (check_ascii > 57) )
  16346. {
  16347. isSuccess = ConfigurationStatus_Rejected;
  16348. }
  16349. else
  16350. {
  16351. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16352. isSuccess = ConfigurationStatus_Accepted;
  16353. }
  16354. }
  16355. else
  16356. {
  16357. isSuccess = ConfigurationStatus_Rejected;
  16358. }
  16359. }
  16360. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16361. {
  16362. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16363. {
  16364. strcpy(str, (const char*)value);
  16365. for(int i = 0; str[i]; i++)
  16366. {
  16367. str[i] = tolower(str[i]);
  16368. }
  16369. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16370. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16371. isSuccess = ConfigurationStatus_Accepted;
  16372. }
  16373. else
  16374. {
  16375. isSuccess = ConfigurationStatus_Rejected;
  16376. }
  16377. }
  16378. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16379. {
  16380. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16381. {
  16382. strcpy(str, (const char*)value);
  16383. for(int i = 0; str[i]; i++)
  16384. {
  16385. str[i] = tolower(str[i]);
  16386. }
  16387. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16388. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16389. isSuccess = ConfigurationStatus_Accepted;
  16390. }
  16391. else
  16392. {
  16393. isSuccess = ConfigurationStatus_Rejected;
  16394. }
  16395. }
  16396. if(strcmp(key, "StopTxnAlignedData") == 0)
  16397. {
  16398. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16399. {
  16400. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16401. isSuccess = ConfigurationStatus_Accepted;
  16402. }
  16403. else
  16404. {
  16405. isSuccess = ConfigurationStatus_Rejected;
  16406. }
  16407. }
  16408. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16409. {
  16410. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16411. {
  16412. check_ascii = value[0];
  16413. if( (check_ascii < 48) || (check_ascii > 57) )
  16414. {
  16415. isSuccess = ConfigurationStatus_Rejected;
  16416. }
  16417. else
  16418. {
  16419. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16420. isSuccess = ConfigurationStatus_Accepted;
  16421. }
  16422. }
  16423. else
  16424. {
  16425. isSuccess = ConfigurationStatus_Rejected;
  16426. }
  16427. }
  16428. if(strcmp(key, "StopTxnSampledData") == 0)
  16429. {
  16430. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16431. {
  16432. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16433. isSuccess = ConfigurationStatus_Accepted;
  16434. }
  16435. else
  16436. {
  16437. isSuccess = ConfigurationStatus_Rejected;
  16438. }
  16439. }
  16440. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16441. {
  16442. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16443. {
  16444. check_ascii = value[0];
  16445. if( (check_ascii < 48) || (check_ascii > 57) )
  16446. {
  16447. isSuccess = ConfigurationStatus_Rejected;
  16448. }
  16449. else
  16450. {
  16451. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16452. isSuccess = ConfigurationStatus_Accepted;
  16453. }
  16454. }
  16455. else
  16456. {
  16457. isSuccess = ConfigurationStatus_Rejected;
  16458. }
  16459. }
  16460. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16461. {
  16462. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16463. {
  16464. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16465. isSuccess = ConfigurationStatus_Accepted;
  16466. }
  16467. else
  16468. {
  16469. isSuccess = ConfigurationStatus_Rejected;
  16470. }
  16471. }
  16472. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16473. {
  16474. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16475. {
  16476. check_ascii = value[0];
  16477. if( (check_ascii < 48) || (check_ascii > 57) )
  16478. {
  16479. isSuccess = ConfigurationStatus_Rejected;
  16480. }
  16481. else
  16482. {
  16483. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16484. isSuccess = ConfigurationStatus_Accepted;
  16485. }
  16486. }
  16487. else
  16488. {
  16489. isSuccess = ConfigurationStatus_Rejected;
  16490. }
  16491. }
  16492. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16493. {
  16494. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16495. {
  16496. check_ascii = value[0];
  16497. if( (check_ascii < 48) || (check_ascii > 57) )
  16498. {
  16499. isSuccess = ConfigurationStatus_Rejected;
  16500. }
  16501. else
  16502. {
  16503. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16504. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16505. TransactionMessageAttemptsValue = atoi(value);
  16506. isSuccess = ConfigurationStatus_Accepted;
  16507. }
  16508. }
  16509. else
  16510. {
  16511. isSuccess = ConfigurationStatus_Rejected;
  16512. }
  16513. }
  16514. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16515. {
  16516. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16517. {
  16518. check_ascii = value[0];
  16519. if( (check_ascii < 48) || (check_ascii > 57) )
  16520. {
  16521. isSuccess = ConfigurationStatus_Rejected;
  16522. }
  16523. else
  16524. {
  16525. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16526. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16527. TransactionMessageRetryIntervalValue = atoi(value);
  16528. isSuccess = ConfigurationStatus_Accepted;
  16529. }
  16530. }
  16531. else
  16532. {
  16533. isSuccess = ConfigurationStatus_Rejected;
  16534. }
  16535. }
  16536. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16537. {
  16538. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16539. {
  16540. strcpy(str, (const char*)value);
  16541. for(int i = 0; str[i]; i++)
  16542. {
  16543. str[i] = tolower(str[i]);
  16544. }
  16545. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16546. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16547. isSuccess = ConfigurationStatus_Accepted;
  16548. }
  16549. else
  16550. {
  16551. isSuccess = ConfigurationStatus_Rejected;
  16552. }
  16553. }
  16554. if(strcmp(key, "WebSocketPingInterval") == 0)
  16555. {
  16556. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16557. {
  16558. check_ascii = value[0];
  16559. if( (check_ascii < 48) || (check_ascii > 57) )
  16560. {
  16561. isSuccess = ConfigurationStatus_Rejected;
  16562. }
  16563. else
  16564. {
  16565. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16566. isSuccess = ConfigurationStatus_Accepted;
  16567. if((atoi(value) == 0) || (atoi(value) >= 10))
  16568. {
  16569. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16570. isSuccess = ConfigurationStatus_Accepted;
  16571. }
  16572. else
  16573. isSuccess = ConfigurationStatus_Rejected;
  16574. }
  16575. }
  16576. else
  16577. {
  16578. isSuccess = ConfigurationStatus_Rejected;
  16579. }
  16580. }
  16581. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16582. {
  16583. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16584. {
  16585. strcpy(str, (const char*)value);
  16586. for(int i = 0; str[i]; i++)
  16587. {
  16588. str[i] = tolower(str[i]);
  16589. }
  16590. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16591. isSuccess = ConfigurationStatus_Accepted;
  16592. }
  16593. else
  16594. {
  16595. isSuccess = ConfigurationStatus_Rejected;
  16596. }
  16597. }
  16598. if(strcmp(key, "AuthorizationKey") == 0)
  16599. {
  16600. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16601. {
  16602. strcpy(str, (const char*)value);
  16603. int strlength = strlen(str);
  16604. char capture[3];
  16605. char stackItem = 0;
  16606. char password[21] = {0};
  16607. printf("String length: %d\n", strlength);
  16608. for(int idx=0; idx<(strlength/2); idx++)
  16609. {
  16610. capture[0] = str[(idx*2)];
  16611. capture[1] = str[(idx*2)+1];
  16612. capture[2] = 0;
  16613. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  16614. sprintf(password,"%s%c", password, stackItem);
  16615. }
  16616. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  16617. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16618. isSuccess = ConfigurationStatus_Accepted;
  16619. }
  16620. else
  16621. {
  16622. isSuccess = ConfigurationStatus_Rejected;
  16623. }
  16624. }
  16625. if(strcmp(key, "SecurityProfile") == 0)
  16626. {
  16627. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16628. {
  16629. check_ascii = value[0];
  16630. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16631. {
  16632. isSuccess = ConfigurationStatus_Rejected;
  16633. }
  16634. else if(check_ascii == 0x33)
  16635. {
  16636. isSuccess = NotSupported;
  16637. }
  16638. else
  16639. {
  16640. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16641. {
  16642. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16643. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16644. isSuccess = ConfigurationStatus_Accepted;
  16645. }
  16646. else
  16647. isSuccess = ConfigurationStatus_Rejected;
  16648. }
  16649. }
  16650. else
  16651. {
  16652. isSuccess = ConfigurationStatus_Rejected;
  16653. }
  16654. }
  16655. if(strcmp(key, "DefaultPrice") == 0)
  16656. {
  16657. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16658. {
  16659. strcpy(str, (const char*)value);
  16660. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16661. isSuccess = ConfigurationStatus_Accepted;
  16662. }
  16663. else
  16664. {
  16665. isSuccess = ConfigurationStatus_Rejected;
  16666. }
  16667. }
  16668. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16669. {
  16670. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16671. {
  16672. strcpy(str, (const char*)value);
  16673. for(int i = 0; str[i]; i++)
  16674. {
  16675. str[i] = tolower(str[i]);
  16676. }
  16677. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16678. isSuccess = ConfigurationStatus_Accepted;
  16679. }
  16680. else
  16681. {
  16682. isSuccess = ConfigurationStatus_Rejected;
  16683. }
  16684. }
  16685. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16686. {
  16687. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16688. {
  16689. strcpy(str, (const char*)value);
  16690. for(int i = 0; str[i]; i++)
  16691. {
  16692. str[i] = tolower(str[i]);
  16693. }
  16694. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16695. isSuccess = ConfigurationStatus_Accepted;
  16696. }
  16697. else
  16698. {
  16699. isSuccess = ConfigurationStatus_Rejected;
  16700. }
  16701. }
  16702. if(strcmp(key, "SystemUptimeSec") == 0)
  16703. {
  16704. isSuccess = NotSupported;
  16705. }
  16706. if(strcmp(key, "FreeVend") == 0)
  16707. {
  16708. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16709. {
  16710. strcpy(str, (const char*)value);
  16711. for(int i = 0; str[i]; i++)
  16712. {
  16713. str[i] = tolower(str[i]);
  16714. }
  16715. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16716. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16717. isSuccess = ConfigurationStatus_Accepted;
  16718. }
  16719. else
  16720. {
  16721. isSuccess = ConfigurationStatus_Rejected;
  16722. }
  16723. }
  16724. if(strcmp(key, "FreeVendIdtag") == 0)
  16725. {
  16726. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16727. {
  16728. strcpy(str, (const char*)value);
  16729. if(strlen(str) <= 20)
  16730. {
  16731. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16732. isSuccess = ConfigurationStatus_Accepted;
  16733. }
  16734. else
  16735. {
  16736. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16737. isSuccess = ConfigurationStatus_Rejected;
  16738. }
  16739. }
  16740. else
  16741. {
  16742. isSuccess = ConfigurationStatus_Rejected;
  16743. }
  16744. }
  16745. if(strcmp(key, "OcppServer") == 0)
  16746. {
  16747. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16748. {
  16749. strcpy(str, (const char*)value);
  16750. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16751. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16752. isSuccess = ConfigurationStatus_Accepted;
  16753. }
  16754. else
  16755. {
  16756. isSuccess = ConfigurationStatus_Rejected;
  16757. }
  16758. }
  16759. if(strcmp(key, "MaintainServer") == 0)
  16760. {
  16761. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16762. {
  16763. strcpy(str, (const char*)value);
  16764. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16765. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16766. isSuccess = ConfigurationStatus_Accepted;
  16767. }
  16768. else
  16769. {
  16770. isSuccess = ConfigurationStatus_Rejected;
  16771. }
  16772. }
  16773. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16774. {
  16775. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16776. {
  16777. strcpy(str, (const char*)value);
  16778. for(int i = 0; str[i]; i++)
  16779. {
  16780. str[i] = tolower(str[i]);
  16781. }
  16782. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16783. isSuccess = ConfigurationStatus_Accepted;
  16784. }
  16785. else
  16786. {
  16787. isSuccess = ConfigurationStatus_Rejected;
  16788. }
  16789. }
  16790. if(strcmp(key, "StatusNotificationInterval") == 0)
  16791. {
  16792. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16793. {
  16794. check_ascii = value[0];
  16795. if( (check_ascii < 48) || (check_ascii > 57) )
  16796. {
  16797. isSuccess = ConfigurationStatus_Rejected;
  16798. }
  16799. else
  16800. {
  16801. if((atoi(value) == 0) || (atoi(value) >= 10))
  16802. {
  16803. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16804. isSuccess = ConfigurationStatus_Accepted;
  16805. }
  16806. else
  16807. isSuccess = ConfigurationStatus_Rejected;
  16808. }
  16809. }
  16810. else
  16811. {
  16812. isSuccess = ConfigurationStatus_Rejected;
  16813. }
  16814. }
  16815. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  16816. {
  16817. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16818. {
  16819. check_ascii = value[0];
  16820. if( (check_ascii < 48) || (check_ascii > 57) )
  16821. {
  16822. isSuccess = ConfigurationStatus_Rejected;
  16823. }
  16824. else
  16825. {
  16826. if(atoi(value) >= 0)
  16827. {
  16828. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value) );
  16829. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  16830. isSuccess = ConfigurationStatus_Accepted;
  16831. }
  16832. else
  16833. isSuccess = ConfigurationStatus_Rejected;
  16834. }
  16835. }
  16836. else
  16837. {
  16838. isSuccess = ConfigurationStatus_Rejected;
  16839. }
  16840. }
  16841. if(strcmp(key, "PowerSharingServerIP") == 0)
  16842. {
  16843. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16844. {
  16845. strcpy(str, (const char*)value);
  16846. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  16847. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  16848. isSuccess = ConfigurationStatus_Accepted;
  16849. }
  16850. else
  16851. {
  16852. isSuccess = ConfigurationStatus_Rejected;
  16853. }
  16854. }
  16855. if(strcmp(key, "EVCCID_PREFIX") == 0)
  16856. {
  16857. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16858. {
  16859. strcpy(str, (const char*)value);
  16860. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  16861. isSuccess = ConfigurationStatus_Accepted;
  16862. }
  16863. else
  16864. {
  16865. isSuccess = ConfigurationStatus_Rejected;
  16866. }
  16867. }
  16868. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  16869. {
  16870. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  16871. {
  16872. if(atoi(value) > modelnameInfo.ratedPower)
  16873. {
  16874. isSuccess = ConfigurationStatus_Rejected;
  16875. }
  16876. else{
  16877. strcpy(str, (const char*)value);
  16878. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  16879. isSuccess = ConfigurationStatus_Accepted;
  16880. }
  16881. }
  16882. else
  16883. {
  16884. isSuccess = ConfigurationStatus_Rejected;
  16885. }
  16886. }
  16887. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  16888. {
  16889. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  16890. {
  16891. if((atoi(value) != 0) && (atoi(value) < 5))
  16892. {
  16893. isSuccess = ConfigurationStatus_Rejected;
  16894. }
  16895. else{
  16896. strcpy(str, (const char*)value);
  16897. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  16898. isSuccess = ConfigurationStatus_Accepted;
  16899. }
  16900. }
  16901. else
  16902. {
  16903. isSuccess = ConfigurationStatus_Rejected;
  16904. }
  16905. }
  16906. #if 0
  16907. //For OCPP Test Case
  16908. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16909. {
  16910. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16911. {
  16912. strcpy(str, (const char*)value);
  16913. for(int i = 0; str[i]; i++)
  16914. {
  16915. str[i] = tolower(str[i]);
  16916. }
  16917. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16918. isSuccess = ConfigurationStatus_Accepted;
  16919. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16920. }
  16921. else
  16922. {
  16923. isSuccess = ConfigurationStatus_Rejected;
  16924. }
  16925. }
  16926. #endif
  16927. #if 1
  16928. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16929. {
  16930. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16931. {
  16932. strcpy(str, (const char*)value);
  16933. for(int i = 0; str[i]; i++)
  16934. {
  16935. str[i] = tolower(str[i]);
  16936. }
  16937. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16938. isSuccess = ConfigurationStatus_Accepted;
  16939. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16940. }
  16941. else
  16942. {
  16943. isSuccess = ConfigurationStatus_Rejected;
  16944. }
  16945. }
  16946. #endif
  16947. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16948. {
  16949. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16950. {
  16951. check_ascii = value[0];
  16952. if( (check_ascii < 48) || (check_ascii > 57) )
  16953. {
  16954. isSuccess = ConfigurationStatus_Rejected;
  16955. }
  16956. else
  16957. {
  16958. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16959. isSuccess = ConfigurationStatus_Accepted;
  16960. }
  16961. }
  16962. else
  16963. {
  16964. isSuccess = ConfigurationStatus_Rejected;
  16965. }
  16966. }
  16967. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16968. {
  16969. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16970. {
  16971. check_ascii = value[0];
  16972. if( (check_ascii < 48) || (check_ascii > 57) )
  16973. {
  16974. isSuccess = ConfigurationStatus_Rejected;
  16975. }
  16976. else
  16977. {
  16978. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16979. isSuccess = ConfigurationStatus_Accepted;
  16980. }
  16981. }
  16982. else
  16983. {
  16984. isSuccess = ConfigurationStatus_Rejected;
  16985. }
  16986. }
  16987. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16988. {
  16989. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16990. {
  16991. strcpy(str, (const char*)value);
  16992. for(int i = 0; str[i]; i++)
  16993. {
  16994. str[i] = tolower(str[i]);
  16995. }
  16996. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16997. isSuccess = ConfigurationStatus_Accepted;
  16998. }
  16999. else
  17000. {
  17001. isSuccess = ConfigurationStatus_Rejected;
  17002. }
  17003. }
  17004. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17005. {
  17006. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17007. {
  17008. check_ascii = value[0];
  17009. if( (check_ascii < 48) || (check_ascii > 57) )
  17010. {
  17011. isSuccess = ConfigurationStatus_Rejected;
  17012. }
  17013. else
  17014. {
  17015. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17016. isSuccess = ConfigurationStatus_Accepted;
  17017. }
  17018. }
  17019. else
  17020. {
  17021. isSuccess = ConfigurationStatus_Rejected;
  17022. }
  17023. }
  17024. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17025. {
  17026. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17027. {
  17028. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17029. isSuccess = ConfigurationStatus_Accepted;
  17030. }
  17031. else
  17032. {
  17033. isSuccess = ConfigurationStatus_Rejected;
  17034. }
  17035. }
  17036. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17037. {
  17038. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17039. {
  17040. check_ascii = value[0];
  17041. if( (check_ascii < 48) || (check_ascii > 57) )
  17042. {
  17043. isSuccess = ConfigurationStatus_Rejected;
  17044. }
  17045. else
  17046. {
  17047. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17048. isSuccess = ConfigurationStatus_Accepted;
  17049. }
  17050. }
  17051. else
  17052. {
  17053. isSuccess = ConfigurationStatus_Rejected;
  17054. }
  17055. }
  17056. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17057. {
  17058. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17059. {
  17060. strcpy(str, (const char*)value);
  17061. for(int i = 0; str[i]; i++)
  17062. {
  17063. str[i] = tolower(str[i]);
  17064. }
  17065. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17066. isSuccess = ConfigurationStatus_Accepted;
  17067. }
  17068. else
  17069. {
  17070. isSuccess = ConfigurationStatus_Rejected;
  17071. }
  17072. }
  17073. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17074. {
  17075. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17076. {
  17077. check_ascii = value[0];
  17078. if( (check_ascii < 48) || (check_ascii > 57) )
  17079. {
  17080. isSuccess = ConfigurationStatus_Rejected;
  17081. }
  17082. else
  17083. {
  17084. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17085. isSuccess = ConfigurationStatus_Accepted;
  17086. }
  17087. }
  17088. else
  17089. {
  17090. isSuccess = ConfigurationStatus_Rejected;
  17091. }
  17092. }
  17093. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17094. return isSuccess;
  17095. }
  17096. int TransactionMessageAttemptsGet(void)
  17097. {
  17098. return TransactionMessageAttemptsValue;
  17099. }
  17100. int FirstHeartBeatResponse(void)
  17101. {
  17102. return FirstHeartBeat;
  17103. }
  17104. int TransactionMessageRetryIntervalGet(void)
  17105. {
  17106. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17107. }
  17108. int ReadHttpStatus(int sock)
  17109. {
  17110. //char c;
  17111. char buff[1024]="",*ptr=buff+1;
  17112. int bytes_received, status;
  17113. DEBUG_INFO("Begin Response ..\n");
  17114. while((bytes_received = recv(sock, ptr, 1, 0))){
  17115. if(bytes_received==-1){
  17116. perror("ReadHttpStatus");
  17117. exit(1);
  17118. }
  17119. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17120. ptr++;
  17121. }
  17122. *ptr=0;
  17123. ptr=buff+1;
  17124. sscanf(ptr,"%*s %d ", &status);
  17125. DEBUG_INFO("%s\n",ptr);
  17126. DEBUG_INFO("status=%d\n",status);
  17127. DEBUG_INFO("End Response ..\n");
  17128. return (bytes_received>0)?status:0;
  17129. }
  17130. //the only filed that it parsed is 'Content-Length'
  17131. int ParseHeader(int sock)
  17132. {
  17133. //char c;
  17134. char buff[1024]="",*ptr=buff+4;
  17135. int bytes_received;
  17136. DEBUG_INFO("Begin HEADER ..\n");
  17137. while((bytes_received = recv(sock, ptr, 1, 0))){
  17138. if(bytes_received==-1){
  17139. perror("Parse Header");
  17140. exit(1);
  17141. }
  17142. if(
  17143. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17144. (ptr[-1]=='\r') && (*ptr=='\n' )
  17145. ) break;
  17146. ptr++;
  17147. }
  17148. *ptr=0;
  17149. ptr=buff+4;
  17150. //printf("%s",ptr);
  17151. if(bytes_received){
  17152. ptr=strstr(ptr,"Content-Length:");
  17153. if(ptr){
  17154. sscanf(ptr,"%*s %d",&bytes_received);
  17155. }else
  17156. bytes_received=-1; //unknown size
  17157. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17158. }
  17159. DEBUG_INFO("End HEADER ..\n");
  17160. return bytes_received ;
  17161. }
  17162. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17163. {
  17164. int result = TRUE;
  17165. char rmFileCmd[100]={0};
  17166. char FilePath[100]={0};
  17167. char ftpbuf[200];
  17168. int systemresult;
  17169. sprintf(FilePath,"/mnt/%s",filename);
  17170. system("ping 8.8.8.8 &");
  17171. if((access(FilePath,F_OK))!=-1)
  17172. {
  17173. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17174. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17175. system(rmFileCmd);
  17176. }
  17177. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17178. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17179. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17180. systemresult = system(ftpbuf);
  17181. if(systemresult != 0)
  17182. {
  17183. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17184. result = FALSE;
  17185. }
  17186. system("pkill ping");
  17187. return result;
  17188. }
  17189. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  17190. {
  17191. int result = TRUE;
  17192. char rmFileCmd[100]={0};
  17193. char FilePath[100]={0};
  17194. char ftpbuf[200];
  17195. int systemresult;
  17196. sprintf(FilePath,"/mnt/%s",filename);
  17197. system("ping 8.8.8.8 &");
  17198. if((access(FilePath,F_OK))!=-1)
  17199. {
  17200. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17201. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17202. system(rmFileCmd);
  17203. }
  17204. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17205. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  17206. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17207. systemresult = system(ftpbuf);
  17208. if(systemresult != 0)
  17209. {
  17210. DEBUG_WARN("scp error!\n");
  17211. result = FALSE;
  17212. }
  17213. system("pkill ping");
  17214. return result;
  17215. }
  17216. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17217. {
  17218. int result = TRUE;
  17219. char rmFileCmd[100]={0};
  17220. char FilePath[100]={0};
  17221. char ftpbuf[200];
  17222. int systemresult;
  17223. sprintf(FilePath,"/mnt/%s",filename);
  17224. system("ping 8.8.8.8 &");
  17225. if((access(FilePath,F_OK))!=-1)
  17226. {
  17227. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17228. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17229. system(rmFileCmd);
  17230. }
  17231. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17232. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17233. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17234. systemresult = system(ftpbuf);
  17235. if(systemresult != 0)
  17236. {
  17237. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17238. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17239. systemresult = system(ftpbuf);
  17240. if(systemresult != 0)
  17241. {
  17242. DEBUG_WARN("FTP download fail!\n");
  17243. result = FALSE;
  17244. }
  17245. }
  17246. system("pkill ping");
  17247. return result;
  17248. }
  17249. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17250. {
  17251. char rmFileCmd[100]={0};
  17252. char FilePath[100]={0};
  17253. char buf[512];
  17254. int systemresult = 0;
  17255. //DEBUG_INFO("filename=%s\n",filename);
  17256. //DEBUG_INFO("url=%s\n",url);
  17257. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17258. if((access(FilePath,F_OK))!=-1)
  17259. {
  17260. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17261. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17262. system(rmFileCmd);
  17263. }
  17264. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17265. if(fp == NULL)
  17266. {
  17267. DEBUG_INFO("log is NULL\n");
  17268. return FALSE;
  17269. }
  17270. else
  17271. {
  17272. fprintf(fp, "%s\n", url);
  17273. fprintf(fp, "%s\n", filename);
  17274. fclose(fp);
  17275. }
  17276. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17277. if(phpFP == NULL)
  17278. {
  17279. DEBUG_INFO("PHP upload fail.\n");
  17280. return FALSE;
  17281. }
  17282. else
  17283. {
  17284. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17285. {
  17286. if(strstr(buf, "result") != NULL)
  17287. {
  17288. sscanf(buf, "result: %d", &systemresult);
  17289. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17290. }
  17291. }
  17292. pclose(phpFP);
  17293. }
  17294. if(systemresult != 1)
  17295. {
  17296. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17297. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17298. if(phpFP == NULL)
  17299. {
  17300. DEBUG_WARN("PHP PUT upload fail.\n");
  17301. return FALSE;
  17302. }
  17303. else
  17304. {
  17305. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17306. {
  17307. if(strstr(buf, "result") != NULL)
  17308. {
  17309. sscanf(buf, "result: %d", &systemresult);
  17310. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17311. }
  17312. }
  17313. pclose(phpFP);
  17314. }
  17315. }
  17316. if(systemresult != 1)
  17317. {
  17318. DEBUG_WARN("PHP PUT upload fail.\n");
  17319. return FALSE;
  17320. }
  17321. return TRUE;
  17322. }
  17323. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17324. {
  17325. int result = FALSE;
  17326. char ftpbuf[200];
  17327. int systemresult;
  17328. /*
  17329. // Domaind name transfer to IP address
  17330. struct hostent* server;
  17331. char *IPbuffer;
  17332. server = gethostbyname(location);
  17333. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17334. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17335. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17336. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17337. systemresult = system(ftpbuf);
  17338. if(systemresult != 0)
  17339. {
  17340. DEBUG_INFO("ftpput error!\n");
  17341. }
  17342. else
  17343. {
  17344. result = TRUE;
  17345. DEBUG_INFO("ftpput OK!\n");
  17346. }
  17347. return result;
  17348. }
  17349. int GetOcppServerURL()
  17350. {
  17351. int result = FALSE;
  17352. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17353. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17354. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17355. struct yuarel url;
  17356. char urlStr[512];
  17357. // OCPPPH only
  17358. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  17359. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  17360. {
  17361. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  17362. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17363. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17364. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  17365. if(yuarel_parse(&url, urlStr) != -1)
  17366. {
  17367. sprintf(OcppProtocol, "%s", url.scheme);
  17368. sprintf(OcppHost, "%s", url.host);
  17369. if(url.path == NULL)
  17370. OcppTempPath[0] = '\0';
  17371. else
  17372. sprintf(OcppTempPath, "%s", url.path);
  17373. if(url.port == 0)
  17374. {
  17375. if(strcmp(OcppProtocol, "wss") == 0)
  17376. OcppPort = 443;
  17377. else
  17378. OcppPort = 80;
  17379. }
  17380. else
  17381. OcppPort = url.port;
  17382. result = TRUE;
  17383. }
  17384. }
  17385. else
  17386. {
  17387. strcpy(OcppHost,"");
  17388. }
  17389. return result;
  17390. }
  17391. int GetOcppPath()
  17392. {
  17393. int result = FALSE;
  17394. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  17395. {
  17396. if(OcppTempPath == NULL)
  17397. {
  17398. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  17399. }
  17400. else
  17401. {
  17402. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  17403. }
  17404. result = TRUE;
  17405. goto End;
  17406. }
  17407. else
  17408. {
  17409. strcpy(OcppPath,"");
  17410. }
  17411. End:
  17412. return result;
  17413. }
  17414. int GetOcppPort()
  17415. {
  17416. return OcppPort;
  17417. }
  17418. int GetOcppConnStatus(void)
  17419. {
  17420. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17421. }
  17422. void SetOcppConnStatus(uint8_t status)
  17423. {
  17424. ShmOCPP16DataPH->OcppConnStatus = status;
  17425. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17426. }
  17427. int GetHeartBeatWithNOResponse(void)
  17428. {
  17429. return HeartBeatWithNOResponse;
  17430. }
  17431. void SetHeartBeatWithNOResponse(void)
  17432. {
  17433. HeartBeatWithNOResponse = 0;
  17434. }
  17435. void GetStartTransactionIdTag(int gun_index)
  17436. {
  17437. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17438. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17439. }
  17440. int GetStartTransactionId(int gun_index)
  17441. {
  17442. return ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17443. }
  17444. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17445. {
  17446. char ch;
  17447. FILE *fptr1;
  17448. int temptransactionId;
  17449. char str[100]={0};
  17450. temptransactionId = 0;
  17451. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17452. {
  17453. DEBUG_INFO("IdTag is empty.\n");
  17454. return temptransactionId;
  17455. }
  17456. /*------ Read the file ----------------*/
  17457. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17458. if (!fptr1)
  17459. {
  17460. DEBUG_INFO("QueueTransactionId file open error.\n");
  17461. //printf(" File not found or unable to open the input file!!\n");
  17462. return temptransactionId;
  17463. }
  17464. ch=fgetc(fptr1);
  17465. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17466. rewind(fptr1);
  17467. if(ch!=EOF)
  17468. {
  17469. // printf("%c",ch);
  17470. while (fgets(str, 100, fptr1) != NULL)
  17471. {
  17472. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17473. if(str[0]=='\0')
  17474. {
  17475. break;
  17476. }
  17477. char *revbuf[8] = {0}; // Variable store string split
  17478. int num = 0;// Quantity after string split
  17479. DEBUG_INFO("Transaction queue data= %s\n", str);
  17480. splitstring(str,",",revbuf,&num); // String split
  17481. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17482. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17483. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17484. DEBUG_INFO("------------------------------\n");
  17485. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17486. {
  17487. if(isStopTransaction)
  17488. {
  17489. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17490. {
  17491. temptransactionId = atoi(revbuf[2]);
  17492. //break;
  17493. }
  17494. }
  17495. else
  17496. {
  17497. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17498. {
  17499. temptransactionId = atoi(revbuf[2]);
  17500. //break;
  17501. }
  17502. }
  17503. }
  17504. }
  17505. }
  17506. else
  17507. DEBUG_INFO("EOF\n");
  17508. fclose(fptr1);
  17509. /*------- End of reading ---------------*/
  17510. return temptransactionId;
  17511. }
  17512. void SetTransactionIdZero(int transactionId)
  17513. {
  17514. char ch;
  17515. FILE *fptr1, *fptr2;
  17516. int temptransactionId = 0;
  17517. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17518. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17519. if (!fptr1)
  17520. {
  17521. //printf(" File not found or unable to open the input file!!\n");
  17522. return ;
  17523. }
  17524. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17525. if (!fptr2)
  17526. {
  17527. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17528. fclose(fptr1);
  17529. return ;
  17530. }
  17531. ch=fgetc(fptr1);
  17532. rewind(fptr1);
  17533. if(ch!=EOF)
  17534. {
  17535. // copy all contents to the temporary file except the specific line
  17536. while (fgets(str, 100, fptr1) != NULL)
  17537. {
  17538. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17539. if(str[0]=='\0')
  17540. {
  17541. break;
  17542. }
  17543. char *revbuf[8] = {0};
  17544. int num = 0;
  17545. strcpy(strtemp, str);
  17546. splitstring(str,",",revbuf,&num);
  17547. if(revbuf[2][0] != '\0')
  17548. {
  17549. temptransactionId = atoi(revbuf[2]);
  17550. if(transactionId != temptransactionId)
  17551. {
  17552. fprintf(fptr2, "%s\n", strtemp);
  17553. }
  17554. }
  17555. }
  17556. }
  17557. fclose(fptr1);
  17558. fclose(fptr2);
  17559. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17560. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17561. /*------ Read the file ----------------*/
  17562. }
  17563. int InternetDisconnect(void)
  17564. {
  17565. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17566. }
  17567. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17568. void storeTempStopTransaction(int gun_index)
  17569. {
  17570. char guid[37]={0};
  17571. int tempIndex = 0;
  17572. char TempStopTransaction[256];
  17573. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17574. DEBUG_INFO("storeTempStopTransaction...\n");
  17575. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17576. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17577. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17578. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17579. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17580. {
  17581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17582. {
  17583. tempIndex = ((gun_index==2) ? 1: 0);
  17584. }
  17585. else
  17586. {
  17587. tempIndex = gun_index;
  17588. }
  17589. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17590. {
  17591. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17592. {
  17593. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17594. }
  17595. }// END OF CHAdeMO_QUANTITY
  17596. }
  17597. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17598. {
  17599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17600. {
  17601. tempIndex = ((gun_index==2) ? 1: 0);
  17602. }
  17603. else
  17604. {
  17605. tempIndex = gun_index;
  17606. }
  17607. for (int index = 0; index < CCS_QUANTITY; index++)
  17608. {
  17609. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17610. {
  17611. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17612. }
  17613. }// END OF CCS_QUANTITY
  17614. }
  17615. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17616. {
  17617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17618. {
  17619. tempIndex = ((gun_index==2) ? 1: 0);
  17620. }
  17621. else
  17622. {
  17623. tempIndex = gun_index;
  17624. }
  17625. for (int index = 0; index < GB_QUANTITY; index++)
  17626. {
  17627. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17628. {
  17629. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17630. }
  17631. }// END OF GB_QUANTITY
  17632. }
  17633. else if(gunType[gun_index] == GUN_TYPE_DO)
  17634. {
  17635. tempIndex = gun_index;
  17636. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17637. {
  17638. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17639. {
  17640. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17641. }
  17642. }
  17643. }
  17644. else
  17645. {
  17646. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17647. {
  17648. tempIndex = 2;
  17649. }
  17650. else
  17651. {
  17652. tempIndex = gun_index;
  17653. }
  17654. for (int index = 0; index < AC_QUANTITY; index++)
  17655. {
  17656. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17657. {
  17658. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17659. }
  17660. }// END OF AC_QUANTITY
  17661. }
  17662. //Stop Transaction Time
  17663. struct timeval tmnow;
  17664. struct tm *tm;
  17665. char buf[28];//, usec_buf[6];
  17666. gettimeofday(&tmnow, NULL);
  17667. time_t t;
  17668. t = time(NULL);
  17669. /*UTC time and date*/
  17670. tm = gmtime(&t);
  17671. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17672. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17673. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17674. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17675. random_uuid(guid);
  17676. /***********************************transactionData******************************************************/
  17677. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17678. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17679. //=================================
  17680. //1. Transaction_Begin
  17681. //=================================
  17682. //============================== Energy.Active.Import.Interval ===========================================
  17683. //=================================
  17684. //2. Transaction_End
  17685. //=================================
  17686. //2.1====================================== Current.Import L1 ==============================================
  17687. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17688. {
  17689. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17690. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17691. {
  17692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17693. {
  17694. tempIndex = ((gun_index==2) ? 1: 0);
  17695. }
  17696. else
  17697. {
  17698. tempIndex = gun_index;
  17699. }
  17700. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17701. {
  17702. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17703. {
  17704. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17705. }
  17706. }// End of for CHAdeMO_QUANTITY
  17707. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17708. }
  17709. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17710. {
  17711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17712. {
  17713. tempIndex = ((gun_index==2) ? 1: 0);
  17714. }
  17715. else
  17716. {
  17717. tempIndex = gun_index;
  17718. }
  17719. for (int index = 0; index < CCS_QUANTITY; index++)
  17720. {
  17721. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17722. {
  17723. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17724. }
  17725. }// End of for CCS_QUANTITY
  17726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17727. }
  17728. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17729. {
  17730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17731. {
  17732. tempIndex = ((gun_index==2) ? 1: 0);
  17733. }
  17734. else
  17735. {
  17736. tempIndex = gun_index;
  17737. }
  17738. for (int index = 0; index < GB_QUANTITY; index++)
  17739. {
  17740. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17741. {
  17742. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17743. }
  17744. }// End of for GB_QUANTITY
  17745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17746. }
  17747. else if(gunType[gun_index] == GUN_TYPE_DO)
  17748. {
  17749. tempIndex = gun_index;
  17750. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17751. {
  17752. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17753. {
  17754. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17755. }
  17756. }
  17757. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17758. }
  17759. else
  17760. {
  17761. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17762. {
  17763. tempIndex = 2;
  17764. }
  17765. else
  17766. {
  17767. tempIndex = gun_index;
  17768. }
  17769. for (int index = 0; index < AC_QUANTITY; index++)
  17770. {
  17771. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17772. {
  17773. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17774. }
  17775. }// End of for AC_QUANTITY
  17776. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17777. }
  17778. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17779. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17780. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17781. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17783. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17784. }
  17785. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17786. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17787. {
  17788. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17789. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17790. {
  17791. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17792. {
  17793. tempIndex = ((gun_index==2) ? 1: 0);
  17794. }
  17795. else
  17796. {
  17797. tempIndex = gun_index;
  17798. }
  17799. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17800. {
  17801. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17802. {
  17803. 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
  17804. }
  17805. }// END OF CHAdeMO_QUANTITY
  17806. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17807. }
  17808. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17809. {
  17810. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17811. {
  17812. tempIndex = ((gun_index==2) ? 1: 0);
  17813. }
  17814. else
  17815. {
  17816. tempIndex = gun_index;
  17817. }
  17818. for (int index = 0; index < CCS_QUANTITY; index++)
  17819. {
  17820. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17821. {
  17822. 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
  17823. }
  17824. }// END OF CCS_QUANTITY
  17825. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17826. }
  17827. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17828. {
  17829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17830. {
  17831. tempIndex = ((gun_index==2) ? 1: 0);
  17832. }
  17833. else
  17834. {
  17835. tempIndex = gun_index;
  17836. }
  17837. for (int index = 0; index < GB_QUANTITY; index++)
  17838. {
  17839. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17840. {
  17841. 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
  17842. }
  17843. }// END OF GB_QUANTITY
  17844. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17845. }
  17846. else if(gunType[gun_index] == GUN_TYPE_DO)
  17847. {
  17848. tempIndex = gun_index;
  17849. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17850. {
  17851. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17852. {
  17853. 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
  17854. }
  17855. }
  17856. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17857. }
  17858. else
  17859. {
  17860. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17861. {
  17862. tempIndex = 2;
  17863. }
  17864. else
  17865. {
  17866. tempIndex = gun_index;
  17867. }
  17868. for (int index = 0; index < AC_QUANTITY; index++)
  17869. {
  17870. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17871. {
  17872. 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
  17873. }
  17874. }// END OF AC_QUANTITY
  17875. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17876. }
  17877. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17878. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17879. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17880. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17881. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17882. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17883. }
  17884. //2.3====================================== Power.Active.Import =========================================
  17885. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17886. {
  17887. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17888. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17889. {
  17890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17891. {
  17892. tempIndex = ((gun_index==2) ? 1: 0);
  17893. }
  17894. else
  17895. {
  17896. tempIndex = gun_index;
  17897. }
  17898. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17899. {
  17900. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17901. {
  17902. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17903. }
  17904. } // End for CHAdeMO_QUANTITY
  17905. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17906. }
  17907. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17908. {
  17909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17910. {
  17911. tempIndex = ((gun_index==2) ? 1: 0);
  17912. }
  17913. else
  17914. {
  17915. tempIndex = gun_index;
  17916. }
  17917. for (int index = 0; index < CCS_QUANTITY; index++)
  17918. {
  17919. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17920. {
  17921. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17922. }
  17923. } // END for CCS_QUANTITY
  17924. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17925. }
  17926. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17927. {
  17928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17929. {
  17930. tempIndex = ((gun_index==2) ? 1: 0);
  17931. }
  17932. else
  17933. {
  17934. tempIndex = gun_index;
  17935. }
  17936. for (int index = 0; index < GB_QUANTITY; index++)
  17937. {
  17938. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17939. {
  17940. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17941. }
  17942. }// END for GB_QUANTITY
  17943. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17944. }
  17945. else if(gunType[gun_index] == GUN_TYPE_DO)
  17946. {
  17947. tempIndex = gun_index;
  17948. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17949. {
  17950. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17951. {
  17952. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17953. }
  17954. }
  17955. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17956. }
  17957. else
  17958. {
  17959. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17960. {
  17961. tempIndex = 2;
  17962. }
  17963. else
  17964. {
  17965. tempIndex = gun_index;
  17966. }
  17967. for (int index = 0; index < AC_QUANTITY; index++)
  17968. {
  17969. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17970. {
  17971. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17972. }
  17973. } // END for AC_QUANTITY
  17974. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17975. }
  17976. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17977. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17978. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17979. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17980. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17981. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17982. }
  17983. //2.4====================================== Voltage L1 ====================================================
  17984. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17985. {
  17986. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17987. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17988. {
  17989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17990. {
  17991. tempIndex = ((gun_index==2) ? 1: 0);
  17992. }
  17993. else
  17994. {
  17995. tempIndex = gun_index;
  17996. }
  17997. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17998. {
  17999. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18000. {
  18001. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18002. }
  18003. } // END OF FOR CHAdeMO_QUANTITY
  18004. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18005. }
  18006. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18007. {
  18008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18009. {
  18010. tempIndex = ((gun_index==2) ? 1: 0);
  18011. }
  18012. else
  18013. {
  18014. tempIndex = gun_index;
  18015. }
  18016. for (int index = 0; index < CCS_QUANTITY; index++)
  18017. {
  18018. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18019. {
  18020. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18021. }
  18022. } // END OF FOR CCS_QUANTITY
  18023. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18024. }
  18025. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18026. {
  18027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18028. {
  18029. tempIndex = ((gun_index==2) ? 1: 0);
  18030. }
  18031. else
  18032. {
  18033. tempIndex = gun_index;
  18034. }
  18035. for (int index = 0; index < GB_QUANTITY; index++)
  18036. {
  18037. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18038. {
  18039. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18040. }
  18041. } // END OF FOR GB_QUANTITY
  18042. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18043. }
  18044. else if(gunType[gun_index] == GUN_TYPE_DO)
  18045. {
  18046. tempIndex = gun_index;
  18047. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18048. {
  18049. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18050. {
  18051. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18052. }
  18053. }
  18054. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18055. }
  18056. else
  18057. {
  18058. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18059. {
  18060. tempIndex = 2;
  18061. }
  18062. else
  18063. {
  18064. tempIndex = gun_index;
  18065. }
  18066. for (int index = 0; index < AC_QUANTITY; index++)
  18067. {
  18068. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18069. {
  18070. 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
  18071. }
  18072. } // END OF FOR AC_QUANTITY
  18073. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18074. }
  18075. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18076. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18077. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18078. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18079. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18080. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18081. }
  18082. //2.5============================================== End SoC =========================================================
  18083. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18084. {
  18085. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18086. 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))
  18087. {
  18088. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18089. {
  18090. tempIndex = ((gun_index==2) ? 1: 0);
  18091. }
  18092. else
  18093. {
  18094. tempIndex = gun_index;
  18095. }
  18096. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18097. {
  18098. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18099. {
  18100. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18101. {
  18102. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18103. }
  18104. }
  18105. }
  18106. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18107. {
  18108. for (int index = 0; index < CCS_QUANTITY; index++)
  18109. {
  18110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18111. {
  18112. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18113. }
  18114. }
  18115. }
  18116. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18117. {
  18118. for (int index = 0; index < GB_QUANTITY; index++)
  18119. {
  18120. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18121. {
  18122. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18123. }
  18124. }
  18125. }
  18126. else if(gunType[gun_index] == GUN_TYPE_DO)
  18127. {
  18128. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18129. {
  18130. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18131. {
  18132. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18133. }
  18134. }
  18135. }
  18136. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18137. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18138. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18139. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18140. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18141. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18142. } // END FOR DC CASE
  18143. }
  18144. //2.6====================================== Current.Import L2 ==============================================
  18145. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18146. {
  18147. // AC 3 phase L2 current
  18148. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18149. {
  18150. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18151. {
  18152. tempIndex = 2;
  18153. }
  18154. else
  18155. {
  18156. tempIndex = gun_index;
  18157. }
  18158. for (int index = 0; index < AC_QUANTITY; index++)
  18159. {
  18160. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18161. {
  18162. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18163. }
  18164. }// End of for AC_QUANTITY
  18165. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18166. }
  18167. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18168. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18169. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18170. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18171. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18172. }
  18173. //2.7====================================== Current.Import L3 ==============================================
  18174. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18175. {
  18176. // AC 3 phase L3 current
  18177. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18178. {
  18179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18180. {
  18181. tempIndex = 2;
  18182. }
  18183. else
  18184. {
  18185. tempIndex = gun_index;
  18186. }
  18187. for (int index = 0; index < AC_QUANTITY; index++)
  18188. {
  18189. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18190. {
  18191. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18192. }
  18193. }// End of for AC_QUANTITY
  18194. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18195. }
  18196. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18197. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18198. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18199. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18200. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18201. }
  18202. //2.9====================================== Voltage L2 ====================================================
  18203. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18204. {
  18205. // AC 3 phase L2 volatge
  18206. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18207. {
  18208. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18209. {
  18210. tempIndex = 2;
  18211. }
  18212. else
  18213. {
  18214. tempIndex = gun_index;
  18215. }
  18216. for (int index = 0; index < AC_QUANTITY; index++)
  18217. {
  18218. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18219. {
  18220. 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
  18221. }
  18222. } // END OF FOR AC_QUANTITY
  18223. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18224. }
  18225. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18226. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18227. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18228. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18229. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18230. }
  18231. //2.10====================================== Voltage L3 ====================================================
  18232. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18233. {
  18234. // AC 3 phase L3 volatge
  18235. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18236. {
  18237. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18238. {
  18239. tempIndex = 2;
  18240. }
  18241. else
  18242. {
  18243. tempIndex = gun_index;
  18244. }
  18245. for (int index = 0; index < AC_QUANTITY; index++)
  18246. {
  18247. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18248. {
  18249. 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
  18250. }
  18251. } // END OF FOR AC_QUANTITY
  18252. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18253. }
  18254. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18255. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18256. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18257. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18258. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18259. }
  18260. //====================== Start SoC ================================
  18261. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18262. {
  18263. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18264. 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))
  18265. {
  18266. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18267. {
  18268. tempIndex = ((gun_index==2) ? 1: 0);
  18269. }
  18270. else
  18271. {
  18272. tempIndex = gun_index;
  18273. }
  18274. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18275. {
  18276. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18277. {
  18278. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18279. {
  18280. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18281. }
  18282. }
  18283. }
  18284. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18285. {
  18286. for (int index = 0; index < CCS_QUANTITY; index++)
  18287. {
  18288. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18289. {
  18290. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18291. }
  18292. }
  18293. }
  18294. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18295. {
  18296. for (int index = 0; index < GB_QUANTITY; index++)
  18297. {
  18298. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18299. {
  18300. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18301. }
  18302. }
  18303. }
  18304. else if(gunType[gun_index] == GUN_TYPE_DO)
  18305. {
  18306. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18307. {
  18308. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18309. {
  18310. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18311. }
  18312. }
  18313. }
  18314. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18315. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18316. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18317. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18318. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18319. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18320. } // END FOR DC CASE
  18321. }
  18322. //======================================== Message create ==============================================
  18323. json_object *StopTransaction = json_object_new_object();
  18324. json_object *transactionDatas = json_object_new_array();
  18325. json_object *sampledValues = json_object_new_array();
  18326. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  18327. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  18328. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  18329. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  18330. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  18331. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18332. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  18333. {
  18334. json_object *transactionData = json_object_new_object();
  18335. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18336. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18337. {
  18338. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18339. {
  18340. json_object *sampledValue = json_object_new_object();
  18341. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18342. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18343. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18344. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18345. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18346. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18347. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18348. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18349. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18350. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18351. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18352. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18353. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18354. json_object_array_add(sampledValues, sampledValue);
  18355. }
  18356. }
  18357. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18358. json_object_array_add(transactionDatas, transactionData);
  18359. }
  18360. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18361. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18362. ,MESSAGE_TYPE_CALL
  18363. ,guid
  18364. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18365. json_object_put(StopTransaction);
  18366. // Check File "TempStopTransaction" Exist
  18367. if((access(TempStopTransaction,F_OK))!=-1)
  18368. {
  18369. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18370. fclose(fopen(TempStopTransaction, "w"));
  18371. }
  18372. else
  18373. {
  18374. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18375. FILE *log = fopen(TempStopTransaction, "w+");
  18376. if(log == NULL)
  18377. {
  18378. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18379. return ;
  18380. }
  18381. else
  18382. {
  18383. fclose(log);
  18384. }
  18385. }
  18386. //Add TempStopTransaction | Update TempStopTransaction
  18387. // open file for writing
  18388. FILE *outfile;
  18389. outfile = fopen (TempStopTransaction, "a");
  18390. //DEBUG_INFO("data = %s\n", queuedata);
  18391. fputs(queuedata, outfile);
  18392. fputs("\n", outfile);
  18393. fclose (outfile);
  18394. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18395. }
  18396. void checkTempStopTransaction(int gun_index)
  18397. {
  18398. FILE *fptr1;
  18399. char ch;
  18400. char str[QUEUE_MESSAGE_LENGTH]={0};
  18401. char guid[37]={0};
  18402. char tempdata[65]={0};
  18403. char connectorStr[2]={0};
  18404. char TempStopTransaction[256];
  18405. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18406. fptr1 = fopen(TempStopTransaction, "r");
  18407. //TempStopTransaction格式: 槍號,StopTransaction封包
  18408. if (!fptr1)
  18409. {
  18410. //printf(" File not found or unable to open the input file!!\n");
  18411. return ;
  18412. }
  18413. ch=fgetc(fptr1);
  18414. //printf(" Now the content of the file %s is : \n",fname);
  18415. rewind(fptr1);
  18416. if(ch!=EOF)
  18417. {
  18418. // copy all contents to the temporary file except the specific line
  18419. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18420. {
  18421. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18422. if(str[0]=='\0')
  18423. {
  18424. break;
  18425. }
  18426. //TempStopTransaction格式: 槍號,StopTransaction封包
  18427. strncpy(connectorStr, str, 1);
  18428. if(atoi(connectorStr) != (gun_index+1))
  18429. {
  18430. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18431. fclose(fptr1);
  18432. return ;
  18433. }
  18434. //random_uuid(guid);
  18435. strncpy(guid, str+6, 36); //copy guid
  18436. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18437. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18438. {
  18439. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18440. }
  18441. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18442. OCPP_insert_transaction_msg(NO, str);
  18443. memset(str,0,ARRAY_SIZE(str));
  18444. }
  18445. }
  18446. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18447. fclose(fptr1);
  18448. remove(TempStopTransaction); // remove the original file
  18449. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18450. }
  18451. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18452. {
  18453. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18454. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18455. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18456. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18457. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18458. }
  18459. int GetWebSocketPingInterval(void)
  18460. {
  18461. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18462. }
  18463. int GetServerSign(void)
  18464. {
  18465. return server_sign;
  18466. }
  18467. uint8_t GetOcppSecurityProfile()
  18468. {
  18469. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18470. }
  18471. void GetOcppChargerBoxId(uint8_t *data)
  18472. {
  18473. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18474. }
  18475. void GetOcppSecurityPassword(uint8_t *data)
  18476. {
  18477. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18478. }
  18479. void SetOcppVersion(uint8_t *version)
  18480. {
  18481. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18482. DEBUG_INFO("ocpp version: %s\n", version);
  18483. if(strstr((char*)version, "ocpp1.6") != NULL)
  18484. {
  18485. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18486. }
  18487. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18488. {
  18489. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18490. system("pkill OcppBackend");
  18491. }
  18492. }
  18493. void SetServerSign(int value)
  18494. {
  18495. server_sign = value;
  18496. }
  18497. int GetBootNotificationInterval(void)
  18498. {
  18499. return BootNotificationInterval;
  18500. }
  18501. int GetInternetConn(void)
  18502. {
  18503. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18504. }
  18505. int GetBackendConnectionTimeout(void)
  18506. {
  18507. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18508. }
  18509. int isConnectorInitMode(int gun_index)
  18510. {
  18511. int tempIndex = 0;
  18512. int result = TRUE;
  18513. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18514. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18515. {
  18516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18517. {
  18518. tempIndex = ((gun_index==2) ? 1: 0);
  18519. }
  18520. else
  18521. {
  18522. tempIndex = gun_index;
  18523. }
  18524. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18525. {
  18526. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18527. {
  18528. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18529. } //end of the same index
  18530. }//end of for CHAdeMO_QUANTITY
  18531. }
  18532. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18533. {
  18534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18535. {
  18536. tempIndex = ((gun_index==2) ? 1: 0);
  18537. }
  18538. else
  18539. {
  18540. tempIndex = gun_index;
  18541. }
  18542. for (int index = 0; index < CCS_QUANTITY; index++)
  18543. {
  18544. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18545. {
  18546. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18547. } //end of the same index
  18548. } // end of for CCS_QUANTITY
  18549. }
  18550. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18551. {
  18552. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18553. {
  18554. tempIndex = ((gun_index==2) ? 1: 0);
  18555. }
  18556. else
  18557. {
  18558. tempIndex = gun_index;
  18559. }
  18560. for (int index = 0; index < GB_QUANTITY; index++)
  18561. {
  18562. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18563. {
  18564. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18565. } //end of the same index
  18566. } // end of for GB_QUANTITY
  18567. }
  18568. else if(gunType[gun_index] == GUN_TYPE_DO)
  18569. {
  18570. tempIndex = gun_index;
  18571. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18572. {
  18573. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18574. {
  18575. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18576. } //end of the same index
  18577. }
  18578. }
  18579. else
  18580. {
  18581. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18582. {
  18583. tempIndex = 2;
  18584. }
  18585. else
  18586. {
  18587. tempIndex = gun_index;
  18588. }
  18589. for (int index = 0; index < AC_QUANTITY; index++)
  18590. {
  18591. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18592. {
  18593. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18594. }//end of the same index
  18595. }//end of for AC_QUANTITY
  18596. }
  18597. return result;
  18598. }
  18599. void refreshProcDogTimer()
  18600. {
  18601. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18602. }
  18603. void InitialSystemValue(void)
  18604. {
  18605. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18606. locallistVersion=0;
  18607. BootNotificationInterval = 0;
  18608. authorizeRetryTimes = 0;
  18609. GunStatusInterval = 10;
  18610. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18611. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18612. //Hear Beat
  18613. HeartBeatWithNOResponse = 0;
  18614. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18615. FirstHeartBeat = 0;
  18616. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18617. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18618. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18619. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18620. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18621. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18622. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18623. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18624. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18625. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18626. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18627. //Status && ConnectorPlugIn Setting
  18628. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18629. {
  18630. ChademoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18631. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18632. }
  18633. for (int index = 0; index < CCS_QUANTITY; index++)
  18634. {
  18635. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18636. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18637. }
  18638. for (int index = 0; index < GB_QUANTITY; index++)
  18639. {
  18640. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18641. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18642. }
  18643. for (int index = 0; index < AC_QUANTITY; index++)
  18644. {
  18645. AcPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18646. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18647. }
  18648. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18649. {
  18650. DoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18651. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18652. }
  18653. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18654. {
  18655. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18656. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18657. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18658. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18659. //memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18660. memset(&ShmOCPP16DataPH->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16DataPH->StatusNotification[gun_index].Status));
  18661. }
  18662. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18663. refreshStartTimer(&clientTime.Heartbeat);
  18664. sleep(1);
  18665. }
  18666. void LWS_Send(char *str)
  18667. {
  18668. //=====================================================
  18669. // Check InternetConn 0: disconnected, 1: connected
  18670. //====================================================
  18671. if(GetOcppConnStatus() == 0)
  18672. {
  18673. DEBUG_INFO("offline now !!!\n");
  18674. return;
  18675. }
  18676. // Only disable isWebsocketSendable operation initiated by charger
  18677. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18678. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18679. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18680. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18681. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18682. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18683. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18684. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18685. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18686. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18687. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18688. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18689. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18690. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18691. {
  18692. isWebsocketSendable = 0;
  18693. }
  18694. pthread_mutex_lock(&lock_send);
  18695. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18696. sprintf((char *)SendBuffer, "%s", str);
  18697. SendBufLen = strlen(str);
  18698. pthread_mutex_unlock(&lock_send);
  18699. lws_callback_on_writable(wsi_client);
  18700. //lws_service(context, 0);
  18701. //sleep(1);
  18702. }
  18703. void LWS_SendNow(char *str)
  18704. {
  18705. //=====================================================
  18706. // Check InternetConn 0: disconnected, 1: connected
  18707. //====================================================
  18708. if(GetOcppConnStatus() == 0)
  18709. {
  18710. DEBUG_INFO("offline now !!!\n");
  18711. return;
  18712. }
  18713. // Only disable isWebsocketSendable operation initiated by charger
  18714. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18715. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18716. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18717. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18718. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18719. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18720. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18721. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18722. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18723. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18724. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18725. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18726. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18727. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18728. {
  18729. isWebsocketSendable = 0;
  18730. }
  18731. pthread_mutex_lock(&lock_send);
  18732. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18733. sprintf((char *)SendBuffer, "%s", str);
  18734. SendBufLen = strlen(str);
  18735. pthread_mutex_unlock(&lock_send);
  18736. lws_callback_on_writable(wsi_client);
  18737. lws_service(context, 0);
  18738. //sleep(1);
  18739. }